TweetFollow Us on Twitter

Messenger
Volume Number:6
Issue Number:4
Column Tag:Programmer's Workshop

Related Info: Dialog Manager

Messenger Delivers

By Kirk Chase, Anaheim, CA

Got The Message?

I was going over the editorial calendar for MacTutor a few weeks back. I was trying to schedule all the fine articles we have on file for future publication. In short, I was trying to do the impossible. But I do get a feeling of “accomplishment” if I come away without feeling terrible for not placing everyone’s article or without a headache.

To continue, I came across Paul Potts article, and scheduled it for April for our “Dialog” issue. I chided myself for not being as good with my modal dialogs. It was so easy to make them a little more friendlier to the user. I decided to come up with a set of useful dialog routines of my own.

When writing an application, there are many dialogs that are similar in nature. They usually have one to three buttons with a message similar to, “Save changes to ”, “You cannot do that!”, or “I am deleting all funds in your Swiss bank account.” If you’re like most people, you have a general dialog box and a general set of routines to put it up with your message in it. It is usually not as robust as it should be. I decided to write a few routines for a general message dialog, Messenger.

Messenger Structure

The heart of messenger is located in the global variable, MInfo. This structure contains the information needed to put up a dialog box with/without an icon and from 0 to 3 buttons. The structure is declared as follows:

/* 1 */

typedef struct DialogInfo {
 short defaultItem;
 int Buttons;
 int dPlace;
 short dIcon;
 Rect IconRect;
 Rect Button1Rect;
 Rect Button2Rect;
 Rect Button3Rect;
 Rect TextRect;
 Rect dRect;
 int Arrange;
 ProcPtr AddFilter;
 Str255 Button1;
 Str255 Button2;
 Str255 Button3;
 Str255 CharEquiv;
 } DialogInfo, *DialogInfoPointer, **DialogInfoHandle;

extern DialogInfo MInfo;

defaultItem: Indicates the button considered the default, or the button which responds to return or enter key. It draws a bold, rounded rectangle around that button.

Buttons: The number of buttons in the dialog. Valid numbers are 0 through 3. If there are 0 buttons then a mouse click, return, or enter will exit the dialog.

dPlace: The dialog is placed in the center or top third of the screen.

dIcon: Specifies the resource ID of the icon or -1 if no icon. You may call the stop, note, or caution icons with their appropriate constant values.

IconRect, Button1Rect, Button2Rect, Button3Rect, TextRect, and dRect: These are the enclosing rectangles for the icon, buttons, text, and dialog. You need only set the top left point to (0,0) and the bottom right point to the width and height of the object. The dialog handler will take care of positioning them for you.

Button1, Button2, Button3: The titles of the buttons to display.

CharEquiv: The character equivalents for the buttons. Two characters may be specified for each button: the first two for button 1, the next two for button 2, and the last two for button 3.

Arrange: This flag has a valid value of HORIZONTAL or VERTICAL, depending on if you want your buttons across the bottom or down the right side.

AddFilter: In addition to the Messenger’s own filter proc which handles character equivalents, updates, and so forth, an additional filter may be designated for further processing. Just pass nil if none, or pass a filter proc of the form:

/* 2 */

pascal Boolean MyFilter(itemHit, theDialog);

itemHit is the item number of the dialog hit; theDialog is the dialog pointer, and you return true if you wish to exit the modal dialog loop and false if not.

Messenger Routines and Globals

menu_height: This is a global of the height in pixels the menu is. It is initialized in InitMessage().

InitMessage: This call is made to put valid values in the MInfo structure. You may modify them to your default dialog style. Call this at the beginning of your application and whenever you wish to reset the default values.

GetMInfo, SetMInfo: I like those calls to GetPort and SetPort, and so I have implemented similar calls. With GetMInfo, you store the old values of MInfo, and with SetMInfo, you set it to your values.

DoMessage: This is the main routine that does all the work. It takes the values in MInfo, creates the dialog, arranges the items, sets the ParamText with the strings you pass, and calls ModalDialog. It returns the number of the last item hit, or 0 if something went wrong.

Message: This is a standard, general dialog routine. It handles those dialogs with familiar button titles such as “OK”.

There are a few other routines, such as positioning a small rectangle in the center or the top third of a larger rectangle (such as screenBits.bounds). The routine will find the top third or center line of the larger rectangle and then centers the smaller rectangle on that line. BoldRect() is used for hiliting the default button. SaveChanges() allows you to pass the file name and a “before closing/quitting” string. AnOSError() is an error handler that returns FALSE if no error is passed to it; otherwise it puts up an appropriate dialog and returns TRUE.

The Code

Messenger.h: This is the header file for Messenger. Include this file in your main routine to call InitMessage, and also include it in every file that makes use of the Messenger routines.

Messenger.c: This is the code for Messenger. I would suggest, again, that you change InitMessage to the set up that you are most likely to use in your application.

About.c: In this file, there are a couple of examples of how to use Messenger. The D_About procedure puts up an About dialog. D_Example procedure shows the use of the additional filter procedure.

Messenger.r: This is the resource file for messenger. Be sure to include it in your resource file. Also, do not use the same IDs for the templates.

Where to go from here?

One direction to go is to improve on the routines. How about three character equivalents? Or get rid of the resource file and do everything in memory? Or add functionality to the positioning routines? Perhaps a few more general dialog routines could be added.

THINK C 4.0 have ‘Estr’ resource types for their class library. These are string resources with English error messages whose IDs correspond to error numbers. For those who are still having difficulty with OOP, perhaps you could extend the error dialog to handle them.

Oh, and try to have meaningful dialogs (I couldn’t help myself).

Listing:  Messenger.h

/********************************
Messenger.h

By Kirk Chase with code from Paul Potts

Created 10/3/89

This is the header file for constants and prototypes of
HandleDialog.c.  This is used to provide a useful set of 
routines to use and modify for working with ModalDialogs
and Alerts
*********************************/

#define _H_Messenger

#define NUL 0
#define nul 0

#define TRUE 1
#define FALSE 0

#define edgeCurve16/* Constants for drawing roundRect */
#define gapBetween -4
#define lineSize 3

#define theReturnKey 13
#define theEnterKey 3

#define MessageBase 3000

#define MTop 50
#define MLeft 120
#define MHeight 135
#define MWidth 328

#define CENTER 2
#define THIRD 3

#define HORIZONTAL 1
#define VERTICAL 0

#define noIcon -1

#define M_BUTTONLESS 5
#define M_OK 1
#define M_OK_CANCEL 2
#define M_YES_NO 3
#define M_YES_NO_CANCEL 4

typedef struct DialogInfo {
 short defaultItem;
 int Buttons;
 int dPlace;
 short dIcon;
 Rect IconRect;
 Rect Button1Rect;
 Rect Button2Rect;
 Rect Button3Rect;
 Rect TextRect;
 Rect dRect;
 int Arrange;
 ProcPtr AddFilter;
 Str255 Button1;
 Str255 Button2;
 Str255 Button3;
 Str255 CharEquiv;
 } DialogInfo, *DialogInfoPointer, **DialogInfoHandle;

extern DialogInfo MInfo;
extern int menu_height;

int MenuBar_Height(void);
void GetMInfo(DialogInfoPointer theMInfo);
void SetMInfo(DialogInfo theMInfo);
void SetUpButtons(int numButtons, short theDefault, char *b1, char *b2, 
char *b3, char *cq);
void SetUpRects(int dHor, int dVer, int bHor, int bVer);
void PositionRect(Rect *smallRect, Rect *largeRect, int HOption, int 
VOption);
void BoldRect(Rect border);
int DoMessage(char *s0, char *s1, char *s2, char *s3);
void InitMessage();
int ArrangeMessage();
int Message(int theType, int theIcon, char *s0, char *s1, char *s2, char 
*s3);
int SaveChanges(char *s1, char *s2);
char AnOSError(OSErr theError, char *s1, char *s2);
Listing:  Messenger.c

/******************************
File Messenger.c
By Kirk Chase with ideas from Paul Potts
Created 9/20/89

Useful routines for dialogs
*****************************/

#include “Messenger.h”
#include “pascal.h”
#include <string.h>

/* variables available globally*/
DialogInfo MInfo;
int menu_height;

/* PROTOTYPES */
/* GLOBAL: void MenuBar_Height(void)
 used to return menu bar height */

/* GLOBAL: void GetMInfo(DialogInfoPointer theMInfo)
 used to get current MInfo state */

/* GLOBAL: void SetMInfo(DialogInfo theMInfo)
 used to set current MInfo state; use like GetPort() and SetPort() with 
GetMInfo() */
 
/* GLOBAL: void SetUpButtons(int numButtons, short theDefault, char *b1, 
char *b2, char *b3, char *cq);
  used to set up button info in MInfo */
  
/* GLOBAL: void SetUpRects(int dHor, int dVer, int bHor, int bVer)
 used to set up rectangles in MInfo */
  
/* GLOBAL: void PositionRect(Rect *smallRect, Rect *largeRect, int HOption, 
int VOption);
 position small rect in large rect */
 
/* GLOBAL: int InitMessage()
 general initialization of message structure */
 
static Rect OriginRect(Rect r);
 /* Moves topleft corner of r to (0,0), while keeping same size, used 
by ArrangeMessage */ 

/* GLOBAL: int ArrangeMessage(int horizontal);
 arranges text, 0 1 icons, 0 3 buttons (horizontally, horizontal = 1; 
vertical, horizontal = 0)
 returns 1 if fine, 0 if problem */
 
/* GLOBAL: void BoldRect(Rect border);
 Puts bold around a rectangle */
 
static void HandleUpdate(DialogPtr theDialog);
 /* Used to handle update events while a modal dialog is active. Used 
by FPROC() */

static pascal Boolean FProc(DialogPtr theDialog,EventRecord *theEvent,int 
*itemHit);
 /* Filter procedure called by ModalDialog to screen dialog events */
 
/* GLOBAL: int DoMessage(char *s0, char *s1, char *s2, char *s3);
 main routine for putting up a message box */
 
/* GLOBAL: int Message(int theType, int theIcon, char *s0, char *s1, 
char *s2, char *s3)
 handles standard M_OK, M_OK_CANCEL, M_YES_NO, M_YES_NO_CANCEL, M_BUTTONLESS 
dialogs */
 
/* GLOBAL: int SaveChanges(char *s1, char *s2)
 handles standard save changes dialog */
 
/* GLOBAL: char AnOSError(OSErr theError, char *s1, char *s2)
 handles standard OS Error dialog */
 
/************************************************************/
/* Function Defined */
/************************************************************/
/* void MenuBar_Height(void)
 used to return menu bar height */
int MenuBar_Height(void)
{
#define mBarHeightGlobal 0xBAA
int *MemPtr;

MemPtr = (int *) mBarHeightGlobal;
if (*MemPtr < 20)
 return(20);
else
 return(*MemPtr);
} /* end MenuBar_Height() */

/************************************************************/
/* void GetMInfo(theMInfo)
 used to get current MInfo state; use like GetPort() and SetPort() with 
SetMInfo() */
void GetMInfo(theMInfo)
DialogInfoPointer theMInfo;
{
theMInfo->defaultItem = MInfo.defaultItem;
theMInfo->Buttons = MInfo.Buttons;
theMInfo->dPlace = MInfo.dPlace;
theMInfo->dIcon = MInfo.dIcon;
theMInfo->IconRect = MInfo.IconRect;
theMInfo->Button1Rect = MInfo.Button1Rect;
theMInfo->Button2Rect = MInfo.Button2Rect;
theMInfo->Button3Rect = MInfo.Button3Rect;
theMInfo->TextRect = MInfo.TextRect;
theMInfo->dRect = MInfo.dRect;
theMInfo->Arrange = MInfo.Arrange;
theMInfo->AddFilter = MInfo.AddFilter;
strcpy((char *) &theMInfo->Button1, (char *) &MInfo.Button1);
strcpy((char *) &theMInfo->Button2, (char *) &MInfo.Button2);
strcpy((char *) &theMInfo->Button3, (char *) &MInfo.Button3);
strcpy((char *) &theMInfo->CharEquiv, (char *) &MInfo.CharEquiv);
} /* end of GetMInfo() */

/************************************************************/
/* void SetMInfo(theMInfo)
 used to set current MInfo state; use like GetPort() and SetPort() with 
GetMInfo() */
void SetMInfo(theMInfo)
DialogInfo theMInfo;
{
MInfo.defaultItem = theMInfo.defaultItem;
MInfo.Buttons = theMInfo.Buttons;
MInfo.dPlace = theMInfo.dPlace;
MInfo.dIcon = theMInfo.dIcon;
theMInfo.IconRect = MInfo.IconRect;
MInfo.Button1Rect = theMInfo.Button1Rect;
MInfo.Button2Rect = theMInfo.Button2Rect;
MInfo.Button3Rect = theMInfo.Button3Rect;
MInfo.TextRect = theMInfo.TextRect;
MInfo.dRect = theMInfo.dRect;
MInfo.Arrange = theMInfo.Arrange;
MInfo.AddFilter = theMInfo.AddFilter;
strcpy((char *) &MInfo.Button1, (char *) &theMInfo.Button1);
strcpy((char *) &MInfo.Button2, (char *) &theMInfo.Button2);
strcpy((char *) &MInfo.Button3, (char *) &theMInfo.Button3);
strcpy((char *) &MInfo.CharEquiv, (char *) &theMInfo.CharEquiv);
} /* end of SetMInfo() */

/************************************************************/
/* SetUpButtons() 
 This sets up text for all 3 buttons and character equivalent, number
 of button and default button of dialog */
void SetUpButtons(numButtons, theDefault, b1, b2, b3, cq)
int numButtons;
short theDefault;
char *b1, *b2, *b3, *cq;
{
MInfo.Buttons = numButtons;
MInfo.defaultItem = theDefault;

strcpy((char *) &(MInfo.Button1), b1);
strcpy((char *) &(MInfo.Button2), b2);
strcpy((char *) &(MInfo.Button3), b3);
strcpy((char *) &(MInfo.CharEquiv), cq);
} /* end of SetUpButtons() */

/************************************************************/
void SetUpRects(dHor, dVer, bHor, bVer)
int dHor, dVer, bHor, bVer;
{
SetRect(&(MInfo.dRect), 0, 0, dHor, dVer);
SetRect(&(MInfo.Button1Rect), 0, 0, bHor, bVer);
SetRect(&(MInfo.Button2Rect), 0, 0, bHor, bVer);
SetRect(&(MInfo.Button3Rect), 0, 0, bHor, bVer);
} /* end SetUpRects() */

/************************************************************/
/* PositionRect()
 Position a smaller rectangle within a larger rectangle 
 Options for horizontal (HOption) and vertical (VOption) are as follows:
 0 : No positioning
 2, CENTER: center small within large
 3, THIRD: position in top (or left) third
 */
void PositionRect(smallRect, largeRect, HOption, VOption)
Rect *smallRect, *largeRect;
int HOption, VOption;
{
int hoffset, voffset;

/* position horizontally if requested */
if (HOption != 0) {
 smallRect->right -= smallRect->left;
 smallRect->left = 0;
 hoffset = (largeRect->right - largeRect->left 
 - smallRect->right) / HOption;
 smallRect->left = largeRect->left + hoffset;
 smallRect->right += smallRect->left;
 }

/* position vertically if requested */
if (VOption != 0) {
 smallRect->bottom -= smallRect->top;
 smallRect->top = 0;
 voffset = (largeRect->bottom - largeRect->top 
 - smallRect->bottom) / VOption;
 smallRect->top = largeRect->top + voffset;
 smallRect->bottom += smallRect->top;
 }
} /* end of PositionRect(smallRect, largeRect, HOption, VOption) */

/************************************************************/
/* InitMessage
 General initialization (centered, stop icon, one button)
 You will need to write your own InitMessage for various messages */
void InitMessage()
{
menu_height = MenuBar_Height();
MInfo.defaultItem = 1;
MInfo.Buttons = 1;
MInfo.dIcon = stopIcon;
MInfo.dPlace = CENTER;
MInfo.Arrange = HORIZONTAL;
MInfo.AddFilter = NULL;

SetRect(&MInfo.dRect, 0, 0, MWidth, MHeight);
PositionRect(&MInfo.dRect, &(screenBits.bounds), CENTER, CENTER);

SetRect(&MInfo.IconRect, 15, 15, 47, 47);
SetRect(&MInfo.Button1Rect, 230, 100, 310, 120);
SetRect(&MInfo.Button2Rect, 125, 100, 205, 120);
SetRect(&MInfo.Button3Rect, 20, 100, 100, 120);
SetRect(&MInfo.TextRect, 65, 15, 315, 80);

strcpy((char *) &(MInfo.Button1), “\pOk”);
strcpy((char *) &(MInfo.Button2), “\pCancel”);
strcpy((char *) &(MInfo.Button3), “\pNo”);
strcpy((char *) &(MInfo.CharEquiv), “\poOcCnN”);
} /* end of InitMessage() */

/************************************************************/
static Rect OriginRect(r)
Rect r;
{
Rect newRect;

SetRect(&newRect, 0, 0, r.right - r.left, r.bottom - r.top);
return newRect;
} /* end of OriginRect(r) */

/************************************************************/
/* ArrangeMessage(); takes MInfo and arranges the rectangles accordingly
 it will look like this:
 __________________       _____________________
 |     _________   |      |     _________      |
 | [I] | Text   |  |      | [I] | Text   | (1) |
 |     |        |  |  or  |     |        |     | 
 |     |________|  |      |     |        | (2) |
 |                 |      |     |        |     |
 |  (1)  (2)  (3)  |      |     |________| (3) |
 |_________________|      |____________________|

 by MInfo.Arrange
 
 if icon is not around, text is moved over, also if there are no buttons, 
text is moved down.
 
 If all goes well it will return 1, if not, it will return 0 */
int ArrangeMessage()
{
#define MARGIN 10
#define WSPACE 15

Rect tRdialog, tRicon, tRtext, tRb1, tRb2, tRb3; /* temporary rectangles 
*/
Rect MaxRect;
intspacing;

/* place rectangles at origin for easier calculations */
tRdialog = OriginRect(MInfo.dRect);
tRicon = OriginRect(MInfo.IconRect);
tRtext = OriginRect(MInfo.TextRect);
tRb1 = OriginRect(MInfo.Button1Rect);
tRb2 = OriginRect(MInfo.Button2Rect);
tRb3 = OriginRect(MInfo.Button3Rect);

/* set non-used buttons to (0,0,0,0) */
switch (MInfo.Buttons) {
 case 0:
 SetRect(&tRb1, 0,0,0,0);
 case 1:
 SetRect(&tRb2, 0,0,0,0);
 case 2:
 SetRect(&tRb3, 0,0,0,0);
 default:
 break;
 }

/* get max rectangle of buttons */
UnionRect(&tRb1, &tRb2, &MaxRect);
UnionRect(&tRb3, &MaxRect, &MaxRect);

tRtext = tRdialog;
InsetRect(&tRtext, MARGIN, MARGIN);

if (MInfo.dIcon >= stopIcon) { /* place icon */
 SetRect(&tRicon, 10, 10, 42, 42);
 if ((tRicon.right > tRdialog.right) || (tRicon.bottom > tRdialog.bottom)) 
{
 return 0;
 }
 /* adjust text for icon and check if there is enough room */
 tRtext.left = tRicon.right + WSPACE;
 if (tRtext.right - tRtext.left < MARGIN) return 0;
 }
else /* no icon */
 SetRect(&tRicon, 0,0,0,0);
 
/* figure spacing for buttons */
if ((MInfo.Buttons > 0) && (MInfo.Arrange == HORIZONTAL)) { /* place 
buttons horizontally */
 spacing = (tRdialog.right - ((tRb1.right + tRb2.right + tRb3.right) 
+ (MARGIN * 2)))/ (MInfo.Buttons + 1);

 /* place buttons */
 SetRect(&tRb1, MARGIN + spacing,
 tRdialog.bottom - tRb1.bottom - MARGIN,
 tRb1.right + MARGIN + spacing,
 tRdialog.bottom - MARGIN);
 SetRect(&tRb2, tRb1.right + spacing,
 tRdialog.bottom - tRb2.bottom - MARGIN,
 tRb2.right + tRb1.right + spacing,
 tRdialog.bottom - MARGIN);
 SetRect(&tRb3, tRb2.right + spacing,
 tRdialog.bottom - tRb3.bottom - MARGIN,
 tRb3.right + tRb2.right + spacing,
 tRdialog.bottom - MARGIN);

 /* adjust text recangle for buttons and check if there is enough text 
room */
 tRtext.bottom = tRdialog.bottom - MARGIN - MaxRect.bottom - WSPACE;
 if (tRtext.bottom - tRtext.top < MARGIN) return 0;
 }

if ((MInfo.Buttons > 0) && (MInfo.Arrange != HORIZONTAL)) { 
 /* place buttons vertically */
 spacing = (tRdialog.bottom - ((tRb1.bottom + tRb2.bottom + tRb3.bottom) 
+ (MARGIN * 2)))/ (MInfo.Buttons + 1);

 /* place buttons */
 SetRect(&tRb1, tRdialog.right - MARGIN - tRb1.right,
 MARGIN + spacing,
 tRdialog.right - MARGIN,
 MARGIN + spacing + tRb1.bottom);
 SetRect(&tRb2, tRdialog.right - MARGIN - tRb2.right,
 tRb1.bottom + spacing,
 tRdialog.right - MARGIN,
 tRb1.bottom + spacing + tRb2.bottom);
 SetRect(&tRb3, tRdialog.right - MARGIN - tRb3.right,
 tRb2.bottom + spacing,
 tRdialog.right - MARGIN,
 tRb2.bottom + spacing + tRb3.bottom);
 /* adjust text recangle for buttons and check if there is enough text 
room */
 tRtext.right = tRdialog.right - MARGIN 
 - MaxRect.right - WSPACE;
 if (tRtext.right - tRtext.left < MARGIN) return 0;
 }
 
/* return new rectangle values */
MInfo.IconRect = tRicon;
MInfo.TextRect = tRtext;
switch (MInfo.Buttons) {
 case 3:
 MInfo.Button3Rect = tRb3;
 case 2:
 MInfo.Button2Rect = tRb2;
 case 1:
 MInfo.Button1Rect = tRb1;
 default:
 break;
 }

return 1;
} /* end of int ArrangeMessage() */

/************************************************************/
/* BoldRect bolds the default button */
void BoldRect(border)
Rect border;
{
PenNormal();
PenSize(lineSize, lineSize);
InsetRect(&border, gapBetween, gapBetween);  
FrameRoundRect(&border, edgeCurve, edgeCurve);
PenNormal();
}

/************************************************************/
/* Handle Update function is used for dialog drawing such as the default 
button */
static void HandleUpdate(theDialog)
DialogPtr theDialog;
{
Rect  itemRect, theRect;
intitemType;
Handle  the_item;
Handle item;

if (MInfo.dIcon >= 0) {
 GetDItem(theDialog, (MInfo.Buttons) + 2, &itemType, &item, &theRect);
 PlotIcon(&theRect, item);
 }
 
if((MInfo.defaultItem > MInfo.Buttons) || (MInfo.defaultItem == 0)) return;

GetDItem(theDialog, MInfo.defaultItem, &itemType, &the_item, &itemRect);
BoldRect(itemRect);
} /* end of HandleUpdate() */

/************************************************************/
/* FProc is used for filtering Dialog events
 Possible uses include:
 1. Keyboarde Equivalents for controls.
 2. Disk initialization.
 3. Refreshing drawings such as default buttons.
 4. Mouse tracking.
 
 Returning TRUE means ModalDialog will exit, False means no */

static pascal Boolean FProc(theDialog,  theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
int*itemHit;
{
long  key;/* Holds the key code */
Point ctr;/* where the mouse click will go */
intDIResult;/* Returned by DIBadMount */
EventRecord diskEvent;    /* Returned by EventAvail, below */

/* Handle disk mounts */
if (GetNextEvent(diskMask, &diskEvent) == TRUE) {
 if (HiWord(diskEvent.message) != 0) {
 diskEvent.where.h = ((screenBits.bounds.right - 
 screenBits.bounds.left) / 2) - (304 / 2);
 diskEvent.where.v = ((screenBits.bounds.bottom - 
 screenBits.bounds.top) / 3) - (104 / 2);
 InitCursor();
 DIResult = DIBadMount(diskEvent.where, diskEvent.message);
 }
 } /* end of if GetNextEvent test for disk events */

switch (theEvent->what) {
 case (updateEvt):
 HandleUpdate(theDialog);
 return FALSE;
 break; 
 
 case (keyDown):
 key = theEvent->message & charCodeMask;
 switch(key) { 
 /* If a key has been pressed, we want to interpret it properly. */
 case theReturnKey: /* Return key */
 case theEnterKey: /* the Enter key */ 
 *itemHit = MInfo.defaultItem;
 return TRUE; /* exit ModalDialog */
 
 /* Put in other Key equivalents, you may wish to check modifies */
 default:
 if ((MInfo.Buttons > 0) && (theEvent->modifiers & cmdKey))
 if ((key == MInfo.CharEquiv[1]) || (key == MInfo.CharEquiv[2])) {
 *itemHit = 1;
 return TRUE;
 }
 if ((MInfo.Buttons > 1) && (theEvent->modifiers & cmdKey))
 if ((key == MInfo.CharEquiv[3]) || (key == MInfo.CharEquiv[4])) {
 *itemHit = 2;
 return TRUE;
 }
 if ((MInfo.Buttons > 2) && (theEvent->modifiers & cmdKey))
 if ((key == MInfo.CharEquiv[5]) || (key == MInfo.CharEquiv[6])) {
 *itemHit = 3;
 return TRUE;
 }
 SysBeep(5);
 return FALSE;
 } /* end of key code switch */
 break;
 
 case (mouseDown):
 /* You can insert your own mouse click
 handlers here.  ModalDialog 
 takes care of mouse events, but you can do
 do special processing.  For example,
 ModalDialog does nothing if a mouse click
 occurs inside a modal dialog but outside
 of a control, but you could do something.
 Keep in mind that you need to wait for 
 mouseUp to determine where the click was 
 completed. This gets complex when you 
 remember that this procedure is not in 
 control, but gets sent each event to filter 
 and/or act upon. You would have to use
 static variables to hold events that you
 want to keep track of between calls to
 your filterProc. */
 
 /* if there are no buttons, dismiss dialog with a mouse click */
 if (MInfo.Buttons == 0) {
 *itemHit = MInfo.defaultItem;
 return TRUE;
 }
 return FALSE;
 break;
 
 case (mouseUp):
 return FALSE;
 break;
 
 default:
 return FALSE;
 break; 
 /* We don’t handle any other types of events, so
 these get sent to ModalDialog unchanged. */
 
 } /* end of switch */
 
} /* end of filterproc function */

/************************************************************/
/* Do Message is a function to handle various 0-3 button message dialogs 

 returns last item hit in dialog or 0 if something went wrong */
int DoMessage( s0, s1, s2, s3)
char *s0, *s1, *s2, *s3;
{
int itemHit, itemNo, itemType;
int exitDialog, DLOGno;
Rect theRect;
DialogPtr theDialog;
Handle theDITL, item, icon;
DialogTHndl dth;
GrafPtr oldWindow;

/* get icon if needed */
DLOGno = MessageBase + MInfo.Buttons;
if (MInfo.dIcon >= 0) {
 DLOGno += 10;
 icon = GetIcon(MInfo.dIcon);
 if (icon == NULL)
 SysBeep(5);
 if (ResError() != noErr) return (0);
 HLock(icon);
 }

dth = (DialogTHndl) GetResource(‘DLOG’, DLOGno);
if (ResError() != noErr) return(0);
HLock((Handle) dth);

GetPort(&oldWindow);

theRect = screenBits.bounds;
theRect.top += menu_hieght;
if ((MInfo.dPlace == CENTER) || (MInfo.dPlace == THIRD))
 PositionRect(&(MInfo.dRect), &(theRect), CENTER, MInfo.dPlace);

/* set up DLOG template’s bounds rectangle */
(*dth)->boundsRect = MInfo.dRect;

theDialog = GetNewDialog(DLOGno, 0, (WindowPtr) -1); /*will get modified 
rect*/
if (theDialog == NULL) {
 SetPort(oldWindow);
 HUnlock((Handle) dth);
 ReleaseResource((Handle) dth);
 return (0);
 }

/* arrange the dialog items in MInfo */
if (ArrangeMessage() == 0) return (0);

/* set up title buttons */
switch (MInfo.Buttons) {
 case 3:
 GetDItem(theDialog, 3, &itemType, &item, &theRect);
 SetCTitle((ControlHandle) item, MInfo.Button3);
 theRect = MInfo.Button3Rect;
 (**((ControlHandle)item)).contrlRect = theRect;
 SetDItem(theDialog, 3, itemType, item, &theRect);
 case 2:
 GetDItem(theDialog, 2, &itemType, &item, &theRect);
 SetCTitle((ControlHandle) item, MInfo.Button2);
 theRect = MInfo.Button2Rect;
 (**((ControlHandle)item)).contrlRect = theRect;
 SetDItem(theDialog, 2, itemType, item, &theRect);
 case 1:
 GetDItem(theDialog, 1, &itemType, &item, &theRect);
 SetCTitle((ControlHandle) item, MInfo.Button1);
 theRect = MInfo.Button1Rect;
 (**((ControlHandle)item)).contrlRect = theRect;
 SetDItem(theDialog, 1, itemType, item, &theRect);
 default:
 break;
 }
 
/* set up icon if needed */
if (MInfo.dIcon >= 0) {
 GetDItem(theDialog, (MInfo.Buttons) + 2, &itemType, &item, &theRect);
 theRect = MInfo.IconRect;
 item = icon;
 SetDItem(theDialog, (MInfo.Buttons) + 2, itemType, item, &theRect);
 }
 
/* set up text */
GetDItem(theDialog, MInfo.Buttons + 1, &itemType, &item, &theRect);
theRect = MInfo.TextRect;
SetDItem(theDialog, MInfo.Buttons + 1, itemType, item, &theRect);
ParamText(s0, s1, s2, s3);

/* set up exit flag and do Modal Dialog */
exitDialog = FALSE;
ShowWindow(theDialog);
SelectWindow(theDialog);
SetPort(theDialog);
FlushEvents(everyEvent, 0);

/* Actual Dialog Loop */
while (!exitDialog) {
 ModalDialog((ProcPtr) FProc, &itemHit);
 
 /* further checks and handling */
 if (MInfo.AddFilter == NULL) {
 if (itemHit <= MInfo.Buttons) exitDialog = TRUE; /* exit on any button 
pressed */
 }
 else {
 exitDialog = CallPascalB(itemHit, theDialog, MInfo.AddFilter);
 }
 
 if (itemHit == MInfo.defaultItem) exitDialog = TRUE; /* exit on default 
item */
 }

/* dispose of resources */
DisposDialog(theDialog);
if (icon != NULL) {
 HUnlock(icon);
 ReleaseResource(icon);
 }
HUnlock((Handle) dth);
ReleaseResource((Handle) dth);
SetPort(oldWindow);
return itemHit;
} /* end of DoMessage( s0, s1, s2, s3) */

/************************************************************/
/* Message() Handles standard ok, ok/cancel, yes/no,
yes/no/cancel dialogs */
int Message(theType, theIcon, s0, s1, s2, s3)
int theType, theIcon;
char *s0, *s1, *s2, *s3;
{
DialogInfotempInfo, oldInfo; /* MInfo stuff */
inttheAnswer;
WindowPtr savePort;

GetMInfo(&oldInfo);

tempInfo.dIcon = theIcon;
tempInfo.Arrange = HORIZONTAL;
tempInfo.AddFilter = NULL;
tempInfo.dPlace = THIRD;
SetMInfo(tempInfo);

switch (theType) {
 case M_BUTTONLESS:
 SetUpButtons(0, 0, “\p”, “\p”, “\p”, “\p”);
 SetUpRects(250, 100, 0, 0);
 break;
 case M_OK:
 SetUpButtons(1, 1, “\pOK”, “\p”, “\p”, “\pOoOoOo”);
 SetUpRects(250, 150, 60, 20);
 break;
 case M_OK_CANCEL:
 SetUpButtons(2, 1, “\pOK”, “\pCancel”, “\p”, “\pOoCcOo”);
 SetUpRects(250, 150, 60, 20);
 break;
 case M_YES_NO:
 SetUpButtons(2, 1, “\pYes”, “\pNo”, “\p”, “\pYyNnOo”);
 SetUpRects(250, 150, 60, 20);
 break;
 case M_YES_NO_CANCEL:
 SetUpButtons(3, 1, “\pYes”, “\pNo”, “\pCancel”, “\pYyNnCc”);
 SetUpRects(300, 150, 60, 20);
 break;
 default:;
 }

GetPort(&savePort);
theAnswer = DoMessage(s0, s1, s2, s3);
SetPort(savePort);
SetMInfo(oldInfo);
return(theAnswer);
} /* end Message() */

/************************************************************/
/* SaveChanges() Handles standard yes/no/cancel.
“Save changes to
<FileName>
<before closing? | before quitting?>” */
int SaveChanges(s1, s2)
char *s1, *s2;
{
int theAnswer;

theAnswer = Message(M_YES_NO_CANCEL, cautionIcon, “\pSave changes to”, 
s1, s2, “\p”);

return(theAnswer);
} /* end SaveChanges() */

/************************************************************/
/* AnOSError() Handles OS error reporting.
Returns TRUE if error, else FALSE (no error) */
char AnOSError(theError, s1, s2)
OSErr theError;
char *s1, *s2;
{
char anError;
Str255 s4;
int theAnswer;

anError = FALSE;
if (theError != noErr) {
 InitCursor();
 anError = TRUE;
 NumToString((long) theError, &s4);
 theAnswer = Message(M_OK, noteIcon,  s1, s2, “\pOS error # is”, (char 
*) &s4);
 }
return(anError);
} /* end AnOSError() */
Listing: About.h

/* *******************************
File: About.h
Function: Header for this Modal Dialog
History: 10/3/89 by Kirk Chase.  
******************************* */
/* Modal Dialog routine */
extern void   D_About(void);
extern void   D_Example(void);
Listing: About.c

/* *******************************
File: About.c
Function: Handle all operations for this Modal Dialog
History: 10/3/89 by Kirk Chase.  
******************************* */
#include “About.h”
#include “String.h”
#include “Messenger.h”

pascal Boolean AboutFilter(itemHit, dptr)
int itemHit;
DialogPtr dptr;
{
return TRUE;
}

pascal Boolean ExampleFilter(itemHit, dptr)
int itemHit;
DialogPtr dptr;
{
int itemType;
Handle item;
Rect box;

if (itemHit == 2) {
 ParamText(“\pThis is changed”,”\pfor YOUR benefit.”, “\p”,”\pOk?”);
 GetDItem(dptr, 3, &itemType, &item, &box);
 InvalRect(&box);
 GetDItem(dptr, 2, &itemType, &item, &box);
 HiliteControl((ControlHandle) item, 255);
 InvalRect(&box);
 }
 
return FALSE;
}

void D_About()
{
DialogInfo AboutInfo, oldInfo;
int dummy;
ProcPtr theFilter;

GetMInfo(&oldInfo);

theFilter = (ProcPtr) &AboutFilter;

AboutInfo.defaultItem = 1;
AboutInfo.Buttons = 1;
AboutInfo.dPlace = THIRD;
AboutInfo.dIcon = noIcon;
SetRect(&AboutInfo.Button1Rect, 0, 0, 80, 20);
SetRect(&AboutInfo.TextRect, 0, 0, 140, 30);
SetRect(&AboutInfo.dRect, 0, 0, 200, 150);
AboutInfo.Arrange = HORIZONTAL;
AboutInfo.AddFilter = theFilter;
strcpy((char *) &AboutInfo.Button1, “\pOK”);
strcpy((char *) &AboutInfo.CharEquiv, “\poOoOoO”);

SetMInfo(AboutInfo);

dummy = DoMessage(“\pMessenger by Kirk Chase”, “\p© 1989 by Kirk Chase”, 
“\pand MacTutor”, “\p”);

SetMInfo(oldInfo);
}

void D_Example()
{
DialogInfo ExampleInfo, oldInfo;
int dummy;
ProcPtr theFilter;

GetMInfo(&oldInfo);

theFilter = (ProcPtr) &ExampleFilter;

ExampleInfo.defaultItem = 1;
ExampleInfo.Buttons = 2;
ExampleInfo.dPlace = THIRD;
ExampleInfo.dIcon = noIcon;
SetRect(&ExampleInfo.Button1Rect, 0, 0, 50, 20);
SetRect(&ExampleInfo.Button2Rect, 0, 0, 100, 20);
SetRect(&ExampleInfo.TextRect, 0, 0, 140, 30);
SetRect(&ExampleInfo.dRect, 0, 0, 300, 100);
ExampleInfo.Arrange = VERTICAL;
ExampleInfo.AddFilter = theFilter;
strcpy((char *) &ExampleInfo.Button1, “\pOK”);
strcpy((char *) &ExampleInfo.Button2, “\p Change Text”);
strcpy((char *) &ExampleInfo.CharEquiv, “\poOcCoO”);

SetMInfo(ExampleInfo);

dummy = DoMessage(“\pExample”, “\pThis is another”, “\pexmaple of”, “\pMessenger”);

SetMInfo(oldInfo);
}
Listing:  Messenger.r

* Messenger.r
* Resource File for Messenger.c
* Created 10/3/89 by Kirk Chase

Messenger.RSRC

* This is the definition for the DIALOG,  Message3N
Type DLOG
 ,3003
Message3N
50  120  183  448
InVisible NoGoAway
1
3003
3003

* This is the item list.
* 3 Buttons, No Icon
Type DITL
 ,3003
4

Button  Enabled
100  230  120  310
Button

Button  Enabled
100  125  120  205
Button

Button  Enabled
100  20  120  100
Button

StaticText
15  15  80  310
^0\0D^1\0D^2\0D^3

Type DLOG
 ,3013
Message3I
50  120  183  448
InVisible NoGoAway
1
3013
3013

* 3 Buttons, Icon
Type DITL
 ,3013
5

Button  Enabled
100  230  120  310
Button

Button  Enabled
100  125  120  205
Button

Button  Enabled
100  20  120  100
Button

StaticText
15  65  80  315
^0\0D^1\0D^2\0D^3

Icon  Enabled
15  15  47  47
41

Type ICON = GNRL 
* This Icon is a dummy icon
 ,41
.H
 00000000 00000000 00000000 00010000
 00028000 00044000 00082000 00101000
 00200800 00400400 00800200 01000100
 02000080 04000040 08000020 10000010
 08000020 0C000060 0E0000E0 070001C0
 03800380 01C00700 00E00E00 00701C00
 00383800 001C7000 000EE000 0007C000
 00038000 00010000 00000000 00000000
.I

Type DLOG
 ,3002
Message2N
50  120  183  448
InVisible NoGoAway
1
3002
3002

* 2 Buttons, No Icon
Type DITL
 ,3002
3

Button  Enabled
100  230  120  310
Button

Button  Enabled
100  125  120  205
Button

StaticText
15  15  80  310
^0\0D^1\0D^2\0D^3

Type DLOG
 ,3012
Message2I
50  120  183  448
InVisible NoGoAway
1
3012
3012

* 2 buttons, Icon
Type DITL
 ,3012
4

Button  Enabled
100  230  120  310
Button

Button  Enabled
100  125  120  205
Button

StaticText
15  65  80  315
^0\0D^1\0D^2\0D^3

Icon  Enabled
15  15  47  47
41

Type DLOG
 ,3001
Message1N
50  120  183  448
InVisible NoGoAway
1
3001
3001

* 1 Button, No Icon
Type DITL
 ,3001
2

Button  Enabled
100  230  120  310
Button

StaticText
15  15  80  310
^0\0D^1\0D^2\0D^3

Type DLOG
 ,3011
Message1I
50  120  183  448
InVisible NoGoAway
1
3011
3011

* 1 Button, Icon
Type DITL
 ,3011
3

Button  Enabled
100  230  120  310
Button

StaticText
15  65  80  315
^0\0D^1\0D^2\0D^3

Icon  Enabled
15  15  47  47
41

Type DLOG
 ,3000
Message0N
50  120  143  448
InVisible NoGoAway
1
3000
3000

* 0 Buttons, No Icon
Type DITL
 ,3000
1

StaticText
15  15  80  310
^0\0D^1\0D^2\0D^3

Type DLOG
 ,3010
Message0I
50  120  143  448
InVisible NoGoAway
1
3010
3010

* 0 Buttons, Icon
Type DITL
 ,3010
2

StaticText
15  65  80  315
^0\0D^1\0D^2\0D^3

Icon  Enabled
15  15  47  47
41

 
AAPL
$102.50
Apple Inc.
+0.25
MSFT
$45.43
Microsoft Corpora
+0.55
GOOG
$571.60
Google Inc.
+2.40

MacTech Search:
Community Search:

Software Updates via MacUpdate

VueScan 9.4.41 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Cloud 3.0.0 - File sharing from your men...
Cloud is simple file sharing for the Mac. Drag a file from your Mac to the CloudApp icon in the menubar and we take care of the rest. A link to the file will automatically be copied to your clipboard... Read more
LibreOffice 4.3.1.2 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
SlingPlayer Plugin 3.3.20.505 - Browser...
SlingPlayer is the screen interface software that works hand-in-hand with the hardware inside the Slingbox to make your TV viewing experience just like that at home. It features an array of... Read more
Get Lyrical 3.8 - Auto-magically adds ly...
Get Lyrical auto-magically add lyrics to songs in iTunes. You can choose either a selection of tracks, or the current track. Or turn on "Active Tagging" to get lyrics for songs as you play them.... Read more
Viber 4.2.2 - Send messages and make cal...
Viber lets you send free messages and make free calls to other Viber users, on any device and network, in any country! Viber syncs your contacts, messages and call history with your mobile device,... Read more
Cocktail 7.6 - General maintenance and o...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
LaunchBar 6.1 - Powerful file/URL/email...
LaunchBar is an award-winning productivity utility that offers an amazingly intuitive and efficient way to search and access any kind of information stored on your computer or on the Web. It provides... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
BBEdit 10.5.12 - Powerful text and HTML...
BBEdit is the leading professional HTML and text editor for the Mac. Specifically crafted in response to the needs of Web authors and software developers, this award-winning product provides a... Read more

Latest Forum Discussions

See All

Rhonna Designs Magic (Photography)
Rhonna Designs Magic 1.0 Device: iOS Universal Category: Photography Price: $1.99, Version: 1.0 (iTunes) Description: Want to sprinkle *magic* on your photos? With RD Magic, you can add colors, filters, light leaks, bokeh, edges,... | Read more »
This Week at 148Apps: August 25-29, 2014
Shiny Happy App Reviews   | Read more »
Qube Kingdom – Tips, Tricks, Strategies,...
Qube Kingdom is a tower defense game from DeNA. You rally your troops – magicians, archers, knights, barbarians, and others – and fight against an evil menace looking to dominate your kingdom of tiny squares. Planning a war isn’t easy, so here are a... | Read more »
Qube Kingdom Review
Qube Kingdom Review By Nadia Oxford on August 29th, 2014 Our Rating: :: KIND OF A SQUARE KINGDOMUniversal App - Designed for iPhone and iPad Qube Kingdom has cute visuals, but it’s a pretty basic tower defense game at heart.   | Read more »
Fire in the Hole Review
Fire in the Hole Review By Rob Thomas on August 29th, 2014 Our Rating: :: WALK THE PLANKUniversal App - Designed for iPhone and iPad Seafoam’s Fire in the Hole looks like a bright, 8-bit throwback, but there’s not enough booty to... | Read more »
Alien Creeps TD is Now Available Worldwi...
Alien Creeps TD is Now Available Worldwide Posted by Ellis Spice on August 29th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Dodo Master Review
Dodo Master Review By Jordan Minor on August 29th, 2014 Our Rating: :: NEST EGGiPad Only App - Designed for the iPad Dodo Master is tough but fair, and that’s what makes it a joy to play.   | Read more »
Motorsport Manager Review
Motorsport Manager Review By Lee Hamlet on August 29th, 2014 Our Rating: :: MARVELOUS MANAGEMENTUniversal App - Designed for iPhone and iPad Despite its depth and sense of tactical freedom, Motorsport Manager is one of the most... | Read more »
Motorsport Manager – Beginner Tips, Tric...
The world of Motorsport management can be an unforgiving and merciless one, so to help with some of the stress that comes with running a successful race team, here are a few hints and tips to leave your opponents in the dust. | Read more »
CalPal Update Brings the App to 2.0, Add...
CalPal Update Brings the App to 2.0, Adds Lots of New Stuff Posted by Ellis Spice on August 29th, 2014 [ permalink ] | Read more »

Price Scanner via MacPrices.net

The Rise of Phablets
Carlisle & Gallagher Consulting Group, a businesses and technology consulting firm focused solely on the financial services industry, has released an infographic depicting the convergence of... Read more
Eddy – Cloud Music Player for iPhone/iPad Fre...
Ukraine based CapableBits announces the release of Eddy, its tiny, but smart and powerful cloud music player for iPhone and iPad that allows users to stream or download music directly from cloud... Read more
A&D Medical Launches Its WellnessConnecte...
For consumers and the healthcare providers and loved ones who care for them, A&D Medical, a leader in connected health and biometric measurement devices and services, has launched its... Read more
Anand Lal Shimpi Retires From AnandTech
Anand Lal Shimpi, whose AnandTech Website is famous for its meticulously detailed and thoroughgoing reviews and analysis, is packing it in. Lal Shimpi, who founded the tech site at age 14 in 1997,... Read more
2.5GHz Mac mini, Apple refurbished, in stock...
The Apple Store has Apple Certified Refurbished 2.5GHz Mac minis available for $509, $90 off MSRP. Apple’s one-year warranty is included, and shipping is free. Read more
13-inch 2.5GHz MacBook Pro on sale for $999,...
B&H Photo has the 13″ 2.5GHz MacBook Pro on sale for $999.99 including free shipping plus NY sales tax only. Their price is $100 off MSRP. Read more
Labor Day Weekend MacBook Pro sale; 15-inch m...
B&H Photo has the new 2014 15″ Retina MacBook Pros on sale for up to $125 off MSRP. Shipping is free, and B&H charges NY sales tax only. They’ll also include free copies of Parallels Desktop... Read more
Labor Day Weekend iPad mini sale; $50 to $100...
Best Buy has the iPad mini with Retina Display (WiFi models) on sale for $50 off MSRP on their online store for Labor Day Weekend. Choose free shipping or free local store pick up. Price is for... Read more
13-inch 1.4GHz MacBook Air on sale for $899,...
Adorama has the new 2014 13″ 1.4GHz/128GB MacBook Air on sale for $899.99 including free shipping plus NY & NJ tax only. Their price is $100 off MSRP. Read more
It’s Official: Apple Issues Invitations To Se...
Apple has issued one of its characteristically cryptic press invitations for a special event to be held at the Flint Center for the Performing Arts in hometown Cupertino on Sept. 9, 2014 at 10:00 am... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.