home *** CD-ROM | disk | FTP | other *** search
- /*
- * SimpleCalc -- Randy Nelson
- * A general class that directly supports a calculator interface
- * Created 8-8-90
- *
- * You may freely copy, distribute an7&use the code in this example.
- * NeXT disclaims any warranty of any kind, expressed or implied, as to
- * its fitness for any particular use.
- */
-
- #import <objc/Object.h>
-
- @interface SimpleCalc:Object
- {
- id infoPanel;
- id helpPanel;
-
- id display; /* a text object -- to show the output and input */
-
- id enterKey; /* outlet to set the key equivalents */
-
- id stringSet; /* our string external to the source */
-
- int operator; /* represents the current operator or zero */
-
- double accumulator; /* a buffer to hold the first number entered */
-
- BOOL numberHasADecimal,
- startingSecondNumber,
- treatingOperationKeyLikeEqualKey,
- noFirstNumber; /* flags that describe the calculators state */
- }
-
- - doInit;
- /* initialize an instance of the class and its flags for start-up
- * also used by the clear all key
- */
-
- - numberKeys:sender;
- /* sent by any number key or the decimal point key in the interface (0-9, .)
- * appends the character to display using appendToDisplay:
- * erases the previous number if startingSecondNumber
- */
-
- - numberDirectFromDisplay:sender;
- /* sent as the action of displayer -- allows direct entry of numbers
- * startingSecondNumber gets YES
- */
-
- - equalsKey:sender;
- /* sent by the equals key in the interface (=)
- * at this point accumulator holds the first number
- * operator holds an int defined to an operation
- * displayer hold the second number
- * performs the operation and leaves the result in the dsplayer
- */
-
- - operationKeys:sender;
- /* sent by the operation keys in the interface (+, -, * and /)
- * sets the value of operation
- * acts like equals to chain a calculation when
- * treatingOperationKeyLikeEqualKey
- */
-
- - clearKeys:sender;
- /* sent by either clear key in the interface(clear, clear all)
- * clear -- zeros the display -- allows re-enetering a number
- * clear all -- resets by calling init
- */
-
- - decimal;
- /* called by numberKeys: when it finds the number is a decimal point
- * checks first if numberHasADecimal already
- * if not -- appendToDisplay: a decimal point
- */
-
- - appendToDisplay:(const char *)theDigit;
- /* sent by objects wanting to append a digit to the number in the displayer
- * removes the leading zeros a zero value displayer has
- * unless there is a decimal point
- */
-
- - appDidInit:sender;
- /* handles some key equivalent setti7&nd orders the window front
- * should be Application's delegate to receive
- */
-
- - windowWillClose:sender;
- /* quits app when window is closed
- * for example -- app's quit menu item can send performClose: to window
- * should be Window's delegate to receive
- */
-
- - infoPanel:sender;
- - helpPanel:sender;
- /* sent by the menu in interface
- * creates the panels as they are needed
- */
- @end
-