TweetFollow Us on Twitter

MacLock
Volume Number:7
Issue Number:7
Column Tag:MacOOPs!

MacLock

By Mark Bykerk-Kauffman, Chico, CA

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

MacLock 1.0: A Complete Object-Oriented Application

[Since the publication of his article, “Intro to OOP,” in the Sept. 1990 issue of MacTutor, Mark Kauffman has left his design/programming job with Burr Brown in Tucson, and moved to Chico, CA. In Chico, Mark is working toward a Bachelors Degree in Computer Science with an emphasis on systems programming. He has owned and programmed a Macintosh since it’s introduction in 1984.]

Origins

While working on a UNIX development system I came across a program called XLOCK. It displayed an icon of an open lock on the screen. When you pressed the lock button on the lock, the lock closed and the system was cut off from further input by the keyboard or mouse. To unlock the system you typed in a password and pressed the Return key. It was possible to change the password by calling up a password dialog. I hadn’t seen a similar program on the Macintosh and I wondered if it would be possible to write a lock program that ran under MultiFinder. Since UNIX is multi-user I knew that somehow the program was taking all input away from the operating system once the lock button was pressed. Could I write a routine with THINK C that took away all input away from MultiFinder while waiting for a password? Could I build an application that looked and acted like XLOCK? I decided that if someone could do it on UNIX system, I could do it on the Mac. This article describes the complete MacLock application that I’ve been distributing as One-Dollar Shareware.

One-Dollar Shareware

When I first started working with microcomputers there was a spirit of generosity among the hobbyists who owned and programmed them. Most games and small applications cost under $50. We still see some of that generosity in the large number of shareware programs available. HyperCard is another example of programmers generosity. In an attempt to keep that spirit alive, I came up with the idea of One-Dollar Shareware. The source code is yours to use; but please, let me continue to distribute the compiled program as shareware. And if you come up with a nifty program, consider distributing it as One-Dollar Shareware. I’ll be glad to send you my dollar.

Dodging The Lawyers

MacLock was written using the class library in THINK C 4.0 and the Resource Editor. Prior to writing this article, I wrote the program following the instructions in the THINK C User’s Manuel in the chapter “The THINK Class Library” under the section “Writing an Application with the THINK Class Library.” When I started to write this article I realized that three of the classes I had defined, CMacLockApp, CMacLockDoc, and CMacLockPane contained large portions of source code from Symantec’s “Starter” demonstration. Rather than worry about copyright laws and whether I was violating Symantec’s License Agreement which states, “You may not in any event distribute any of the source files provided or licensed as part of the software,” I decided to rewrite my source code so that the classes I defined contained only the code necessary for them to function.

Sounds like a lot of work doesn’t it? It wasn’t. What I did to solve the problem illustrates the beauty of one of the features of object-oriented programming, inheritance. Instead of having CMacLockApp, CMacLockDoc and CMacLockPane (the C prefix indicates a class structure) be direct descendants of CApplication, CDocument and CPane I made them subclasses of CStarterApp, CStarterDoc and CStarterPane in the “Starter” demonstration folder. Writing an application this way follows one of the basic rules of object oriented programming. Build new objects that are based on similar objects then write just the few methods and instance variables necessary to make your application unique. Programming this way means that it’s not necessary for CMacLockApp to contain an Exit method or a SetUpFileParameters method, because MacLock doesn’t act any differently than the Starter demonstration when responding to an Exit or a SetUpFileParameters message. Nor do CMacLockDoc and CMacLockPane need to contain any method whose function has already been defined in the Starter demonstration and is not unique to the MacLock application.

Before I give step by step instructions on how to build the MacLock application, I’d like to discuss some other basic ideas that gave me guidance designing an object-oriented program.

Thinking OOP

Another rule of object-oriented programming is that you must think in terms of objects. In his book, Object-oriented Software Construction, Dr. Bertrand Meyer says in the preface that object-oriented design means that you base your software on objects NOT on the actions your computing system takes on those objects. Why think object-oriented? Dr. Meyer spends the first three chapters of his book explaining why large function-oriented programs have problems with correctness, robustness, extendibility, reusability and compatibility. In the fourth chapter he defines an object and how using objects to design software solves those problems. Since there’s not enough space here to write a book, what follows are just a few guidelines I found useful while writing an object-oriented program.

First, replace global variables with global objects. Let me give an example. There is a file, “Commands.h”, that Symantec uses to define all the commands to which a common Macintosh application responds. The object-oriented way of implementing Commands would have been to define a class CCommands(based on an existing class if possible) then creating an object, gCommands, at run time with the statement gCommands=new(CCommands). What would our software do with the object gCommands? We could send it messages like cmdOpen, cmdSave, cmdNew and expect a number back. And we would need to destroy it when we are done using it.

You might ask, “Why would I go to the trouble of creating an object to implement something as simple as a global list of commands and their corresponding values?” Another reason object-oriented programming works better than function-oriented programming is it’s extendibility. What if tomorrow some new part Symantec’s system required that Commands.h did more than return an integer for each command, like wait until several commands were sent before responding? What if they needed the integer returned to depend on the order of commands recieved? It would be easy to extend a class CCommands to include these functions without affecting the rest of the software. Of course the likelihood of Commands.h needing to do these other things is small, so in THINK C the quickest and easiest way to implement what was necessary is to create an include file of simple global constants. But some of the new purely object-oriented languages like Eiffel require that anything global to a software system be an object. And if purely object-oriented design fulfills Dr. Meyer’s promise of drastically reducing seventy percent of the software costs associated with maintenance, we had better start to work that way.

When I designed MacLock, the above idea was reinforced by what happened to me when I started implementing the password. I tried to have the password be a global variable. There were problems; the password kept disappearing. The system would not work correctly until I created a password object.

Second, use what’s already there. Symantec gave us a lot more than menus, windows and buttons with their Class Library. We have CCollection, CList, CChore, CEditText, CPane and more. You will find that most of what you want your application to do is already defined by these classes and that all you need to do is create classes that inherit properties from these then add or modify a method here and there.

Writing your program this way will save you a lot of time. Initially you will spend time learning the THINK C class library, but that only happens ONCE.

Third, if you use a resource, you should create an object. I discovered this rule while working on routines to read in the password from the keyboard and open the lock. Placing the dialog box and everything else concerning the password into an object made the program a lot easier to work with. Another place I should use an object, but haven’t, is for the lock icon that opens and closes. It’s still easier for me to see objects after I’m done writing a program. I’ve left the code the way it is so that you can see the difference between object-oriented programming (CPassword) and function-oriented programming (the lock icon).

The following paragraphs describe how to set up the MacLock project. It is a bit different than a standard project, so please follow the instructions carefully. You should do things in the order given and test the application after each section.

Arrange the Folders Used by MacLock

Because the MacLock Application, Document and Pane classes are inherited from the Starter demonstration you will need to move the folder “TCL Demos” into the folder “Think C”. When the THINK C compiler looks for #include files it looks in your project folder and in the THINK C folder. Moving the TCL Demos folder into the THINK C folder lets the compiler find the Starter demonstration code it needs. Before building the MacLock project you should compile and run the Starter Demo one time. If you don’t, when you create the MacLock project the Search & Replace function won’t see the .h files as part of your project. Create a working copy of the Starter Folder, which is in the TCL Demos Folder, as follows: Copy the Starter folder, change the new folder name from “Copy of Starter Folder” to “MacLock Folder”. Move the MacLock folder from the “TCL Demos” folder into the folder that holds all of your project folders.

Build the MacLock Project

Now open the MacLock project (MacLock.Π) and use the THINK C “Find...” command in the Search menu to find and replace all occurrences of “Starter” with “MacLock” in all of the files used by the project. Be sure to check the “Multi-File Search” box when starting your search then press the “Check All” button. When you are done with the search and replace, you should have a bunch of files with open edit windows on the screen. Do a “Save As...” for each file. Replace all occurrences of “Starter” in the file names with “MacLock” before saving. Close each edit window after you save it with the new file name.

It’s a good time to test run your new project. After you’ve run it, quit THINK C and trash all the the files in the MacLock Folder with “Starter” in their name. Now you are going to change the file “MacLock.Π.rsrc” to give the project the resources unique to MacLock.

Modify the Resource Table

Double click on “MacLock.Π.rsrc” and the program ResEdit should open it. If you’ve never used ResEdit much, follow these instructions as you look at Figures 1 through 16. If you’re an old hand at ResEdit, just look at the Figures. A figure is worth a thousand words.

Step number 1 and 2 create the resources that define the lock button.

Step 1: Double click on (I’ll just say open from here on.) “CNTL” in the “MacLock.Π.rsrc” window. Select “New” from the “File” menu. Select “Get Info” from the “File” menu. Use the tab key to move between fields. Change the “ID:” field to 2047. Type “LOCK” into the “Name:” field. Close the “Info for CNTL 2047” window.

Step 2: Open “CNTL “Lock” ID = 2047". Use the tab key or the mouse and the keyboard to edit the “CNTL “LOCK” ID” window so that it looks like the one in Figure 2. Close the “CNTL “LOCK” ID” window. Close the “CNTLs” window.

Figure 1.

Figure 2.

Figure 3

Figure 4.

Step numbers 3 through 9 create the resources necessary for the “Change Password” dialog.

Step 3: Open the “DITL” resource. Select “New” from the “File” menu. Select “Get Info” from the “File” menu. Edit the “Info for DITL 2048” window so that it looks like Figure 3. Close the window.

Step 4: Open the “DITL “Password”” resource. Select “New” from the “File” menu. Modify the window titled “Edit DITL Item #1” so that it looks the same as Figure 4. Close the window.

Step 5: Select “New” from the “File” menu again. Edit the window titled “Edit DITL Item #2” so that it matches the window in Figure 5. Be sure to type the word “Password” into the “Text” field. Close the window.

Step 6: Once again, select “New” from the “File” menu. Change the window titled “Edit DITL Item #3” so that it is the same as the window shown in Figure 6. Close the window.

Step 7: At this point, the window titled “DITL “Password” ID = 2048" should look the same as the window shown in Figure 7. Close the window. Now is a good time to save your work. Close the window titled “DITLs.” Close the window titled “MacLock.Π.rsrc”. Answer yes to the “Save “MacLock.Π.rsrc before closing?” alert box. Now reopen “MacLock.Π.rsrc.”

Step 8: Open the “DLOG” resource. Select “New” from the “File” menu. Select “Get Info” from the “File” menu. Change the “ID” field to 2048. Type Password into the “Name:” field. Your window should look like the on shown in Figure 8. Close the “Get Info” window.

Step 9: Select “Open as Template” from the “File” menu. Click “OK” in the “Select Template” dialog box. Edit the “DLOG Template” window so that it looks like the window shown in Figure 9. Close the “DLOG Template” window. Close the “DLOG” resource window.

Figure 5.

Figure 6.

Figure 7.

Step numbers 10 through 14 create the resources for the open and closed lock icons.

Step 10: Open the “ICON” resource. Select “New” from the “File” menu. Select “Get Info” from the “File” menu. Type 2049 into the “ID:” field. The “Info for ICON” window should look like the window shown in Figure 10. Close the window.

Step 11: Use the mouse to create the open lock icon shown in Figure 11. When you have it, select “Copy” from the “Edit” menu then close the “Icon ID = 2049” window.

Step 12: Select “New” from the “File” menu. Select “Paste” from the “Edit” menu. Modify the open lock icon to look like the closed lock icon shown in Figure 12.

Step 13: Select “Get Info” from the “File” menu. Type 2050 into the “ID:” field. Your window should look like the one shown in Figure 13. Close the “Info for ICON 2050” window. Close the “Icon ID = 2050” window.

Step 14: You should have two ICONS in the “ICONs from MacLock” window that look like the icons shown in figure 14. Now is a good time to save your work. Close the “ICONs from MacLock” window. Close the window titled “MacLock.Π.rsrc”. Answer yes to the “Save “MacLock.Π.rsrc before closing?” alert box. Now reopen “MacLock.Π.rsrc.”

Figure 8.

Figure 9.

Figure 10.

Figure 11.

Figure 12.

Step numbers 15 through 17 create the resources for the MacLock menu bar item.

Step 15: Open the “MBAR” resource. Open “MBAR ID = 1.” Single click on the bottom row of asterisks. Select “New” from the “File” menu. Type the number 4 into the new “Menu res ID” field. Your window should look like the “MBAR ID = 1” window shown in Figure 15. Close the window. Close the “MBARs” window.

Step 16: Open the “MENU” resource. Select “New” from the “File” menu. Select “Get Info” from the “File” menu. Edit the window so that it looks like the “Info for Menu 4” window in Figure 16. Close the window.

Step 17: Edit the window titled “Menu “MacLock” ID = 4" so that it looks like the window shown in Figure 17. NOTE: To add the MenuItem field and the fields that follow, you need to single click on the bottom row of asterisks then select “New” from the “File” menu.

Type in the MacLock Source Code

Open the file “MacLock.Π. Before you start changing the source code files to look like the source code listings that follow this article, you need to select the “Source” menu and “Add...” the following files, that are in the Starter Demo Folder, to the project : CStarterApp, CStarterDoc and CStarterPane. Now open and edit each of the source code files, MacLock.c, CMacLockApp.h, CMacLockApp.c, CMacLockDoc.h, CMacLockDoc.c, CMacLockPane.h, and CMacLockPane.c to look like the source code listings that follow this article. All of the files have comments explaining their purpose and function. To understand the operation of the code, you should read the comments and experiment by changing parts that you don’t understand. You also need to select “New” from the THINK C “File” menu to create each of the files, CAboutMacLock.h, CAboutMacLock.c, CPassword.h, CPassword.c, and MacLockCmds.h. After you’ve typed in and saved each of the dot-c files, you should select the THINK C “Source’ menu and “Add...” it to the project.

Congratulations! You’ve just finished building a complete Macintosh application. Run it!

Figure 13.

Figure 14.

Figure 15.

Figure 16.

Figure 17.

Possibilities!

You’ve just created a complete Macintosh application using THINK C. It’s only a beginning. Here’s a list of several ideas that could improve the program. How about changing the password object so that it doesn’t block out the events that are sent to screen saver programs? Why not make the open and closed lock icons into an object? Write code that saves the current password as part of a resource and reads that password in the next time MacLock is started. Several people have written me requesting changes that would allow the user to lock the system at startup. I’ll be making all of these changes and releasing new versions as time allows. I hope you find the my code useful for projects you are working on. Have fun with it and keep on programming!

References

Meyer, B. (1988). Object-oriented Software Construction. Hertfordshire: Prentice Hall Inc.

Symantec. (1989). Think C User’s Manuel.

Listing:  CMacLockApp.h

/*****
 *
 * FILE:CMacLockApp.h
 * Programmer:   Mark Bykerk Kauffman
 * Date:1/91
 * Purpose: 
 * Application class for MacLock.
 *
 *****/

#define _H_CMacLockApp    

/* Parent Class */
#include "CStarterApp.h"  

struct CMacLockApp : CStarterApp {
/* Methods */
 void IMacLockApp(void);
 void StartUpAction(short numPreloads);
 void MakeDesktop(void);

 void UpdateMenus(void);
 void DoCommand(long theCommand);
 void CreateDocument(void);
 void OpenDocument(SFReply *macSFReply);
};
Listing:  MacLockCmds.h

/*****
 *
 * FILE:MacLockCmds.h
 * Programmer: Mark Bykerk Kauffman
 * Date:1/90
 * Purpose:
 * Commands implemented by the MacLock Application
 *
 *****/
 
#define _H_MacLockCmds

#define cmdPassword2048   
Listing:  CPassword.h

/*****
 *
 * FILE:CPassword.h
 * Programmer: Mark Bykerk Kauffman
 * Date:1/91
 * Purpose: 
 * Interface for the CPassword class.
 * 
 *****/
 
#define _H_CPassword

/* Parent class  */
#include "CObject.h" 

struct CPassword : CObject {
 /* Instance Variables */
 char   aPassword[255];
 
 /* Methods */
 void   IPassword(void);
 void   Dispose(void);
 
 void   ChangePassword(void);
 void   WaitForPassword(void);
};
Listing:  CPassword.c

/*****
 *
 * FILE:CPassword.c
 * Programmer: Mark Bykerk Kauffman
 * Date:1/90
 * Purpose:
 * The CPassword class methods.    
 * Copyright © 1990 Mark Bykerk Kauffman.
 * SUPERCLASS = CObject 
 *
 *****/

#include "CPassword.h"
#include <string.h>/* Use the ANSI strcmp function in WaitForPassowrd. 
*/

/*** Class Constants ***/
#define PASSWORD_DLOG_ID  2048
#define NIL_POINTER0L
#define MOVE_TO_FRONT-1L
#define OK_BUTTON1
#define TEXT_BOX 3

/**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S 
****/
/***
*
* IPassword
*
*Initialize a Password object
***/
void  CPassword::IPassword()
{
 aPassword[0]='\0';
}

/***
*
* Dispose {OVERRIDE}
*
*Dispose of Password by releasing all its resources
***/
void  CPassword::Dispose()
{
 inherited::Dispose();  
}

/***
*
* ChangePassword
*
*Display a Dialog Box that lets the user change 
* the instance variable aPassword.
*
***/
void  CPassword::ChangePassword()
{
 DialogPtrpasswordDialog;
 int    itemHit, dialogDone = FALSE;
 int    itemType;
 Rect   itemRect;
 Handle itemHandle;
 char   *PtPassword;

 PtPassword = this->aPassword;
 CtoPstr(PtPassword);
 passwordDialog = GetNewDialog(PASSWORD_DLOG_ID,NIL_POINTER,
 MOVE_TO_FRONT);
 GetDItem(passwordDialog,3,&itemType,&itemHandle,
 &itemRect);
 SetIText(itemHandle,PtPassword);
 SelIText(passwordDialog,3,0,32767);
   
 while ( dialogDone == FALSE )
 {
 ModalDialog(NIL_POINTER, &itemHit);
 switch ( itemHit )
 {
 case   OK_BUTTON:
 dialogDone = TRUE;
 break;
 }
 }
 GetIText(itemHandle,&aPassword);
 PtoCstr(PtPassword);
 DisposDialog(passwordDialog); 
}

/***
* WaitForPassword
*
*Waits for the user to type in thePassword
* followed by a carriage return.
*
***/
void  CPassword::WaitForPassword()
{
 int    i=0;
 char   theGuess[255];
 char   *ptTheGuess,charCode;
 EventRecordtheEvent;
 char   *PtPassword;
 
 Booleandone;
 BooleanendOfLine;
 
 PtPassword = this->aPassword;
 ptTheGuess = theGuess;
 done = FALSE;
 
 do
 {
 endOfLine = FALSE;
 i=0;
 theGuess[0]='\0';
 FlushEvents(everyEvent, 0);
 while (endOfLine==FALSE)
 {
 GetOSEvent(everyEvent,&theEvent);
 switch (theEvent.what)
 {
 case keyDown:
 charCode = BitAnd(theEvent.message,charCodeMask);
 if (charCode != '\r')
 {
 theGuess[i] = charCode;
 ++i;
 theGuess[i]='\0';
 }
 else
 {
 endOfLine=TRUE;
 }
 break;
 default:
 done=FALSE;
 }
 }
 SysBeep(20);
 } while (strcmp(PtPassword,ptTheGuess)!=0); 
}
Listing:  CMacLockPane.h

/*****
 *
 * FILE:CMacLockPane.h
 * Programmer: Mark Bykerk Kauffman
 * Date:1/91
 * Purpose:
 * Pane class for the MacLock application.
 *
 *****/

#define _H_CMacLockPane 
 
/* Parent Class */
#include <CStarterPane.h>

#include <CButton.h>

struct CMacLockPane : CStarterPane {
 /* Instance Variables  */
 CButton  *LockButton;
 Handle displayedIcon;
 Handle closedLockIcon;
 Rect   LockLocation;
 Handle openLockIcon;
 
 /* Methods */
 void   IMacLockPane(CView *anEnclosure,
   CBureaucrat *aSupervisor,
 short aWidth, short aHeight,
 short aHEncl, short aVEncl,
 SizingOption aHSizing,
   SizingOption aVSizing);
 void   Dispose(void);
 void   DoCommand(long theCommand);
 void   Draw(Rect *area);
};
Listing:  CMacLockPane.c

/*****
 * FILE:CMacLockPane.c
 * Programmer: Mark Bykerk Kauffman
 * Copyright © 1990.
 * Date:1/91
 * Purpose:
 * Pane methods for MacLock.
 * PARENTCLASS = CStarterPane 
 *
 *****/
 
#include <string.h> 
#include "CMacLockPane.h"
#include "CPassword.h"

/* Global Variables used by objects of this class. */
/* commands */
#define LockIt   5000

/* resource IDs  */
#define ButtonID12047
#define openLockRsrc 2049
#define closedLockRsrc  2050

/* The single password object global to the application. */
extern  CPassword*gThePassword; 

/* METHOD IMPLEMENTATIONS */

/*****
 * IMacLockPane
 *
 * MacLockPane's initialization method.
 * Setup the lock's location for the Draw method,
 *  get the icons from the resource table, initialize
 *  the window the lock is displayed in,
 * and create a button object.
 *
 *****/
void CMacLockPane::IMacLockPane(CView *anEnclosure, CBureaucrat *aSupervisor, 
short aWidth, short aHeight, short aHEncl, short aVEncl,
 SizingOption aHSizing, SizingOption aVSizing)
{
 SetRect(&LockLocation,10,10,74,74);

 openLockIcon = GetIcon(openLockRsrc);
 closedLockIcon = GetIcon(closedLockRsrc);
 displayedIcon = openLockIcon;
 CPanorama::IPanorama(anEnclosure, aSupervisor, aWidth,
  aHeight,aHEncl, aVEncl, aHSizing,
  aVSizing);
 LockButton = new(CButton);
 LockButton->IButton(ButtonID1, this, this);
 LockButton->SetClickCmd(LockIt);
 SetWantsClicks(TRUE);
}

/*****
 * Dispose
 *
 * MacLockPane's dispose method.
 * Get rid of the lock button object then call
 *  the inherited dispose method.
 *
 *****/
void CMacLockPane::Dispose(void)
{
 LockButton->Dispose(); 
 inherited::Dispose();
}

/*****
 * DoCommand
 *
 * MacLockPane's DoCommand method. When the lock button
 *  is pressed, display the closed lock icon and
 * wait for the password.  After the password is
 *  entered, display the open lock icon.
 *
 *****/
void CMacLockPane::DoCommand(long theCommand)
{
 Rect Location;
 char answer[255]="\0";

 switch (theCommand) 
 {
 case LockIt:  this->Prepare();
 displayedIcon = closedLockIcon;
 SysBeep(20);
 Draw(&frame);  
/* frame is an instance variable defined in CPane.*/
 gThePassword->WaitForPassword();
 displayedIcon = openLockIcon;
 Draw(&frame);  
 break;

 default: inherited::DoCommand(theCommand);
 break;
 }
}

/***
 * Draw
 *
 * MacLockPane's Draw method.
 * 
 *
 ***/
void CMacLockPane::Draw(Rect *area)
{
 Rect Location;

 /* draw your stuff */
 Location = this->LockLocation;
 PlotIcon(&Location,displayedIcon);
}
Listing:  CMacLockDoc.h

/****
 *
 * FILE:CMacLockDoc.h
 * Programmer: Mark Bykerk Kauffman
 * Date:1/91
 * Purpose:
 * Document class for a MacLock.
 *
 ****/
#define _H_CMacLockDoc    

/* Parent class. */
#include <CStarterDoc.h>

struct CMacLockDoc : CStarterDoc {
 /* Methods */
 void   IMacLockDoc(CBureaucrat *aSupervisor, Boolean printable);
 void   BuildWindow(Handle theData);

 /* Dispose, DoCommand, Activate, Deactivate,
  NewFile and OpenFile are inherited.
 */
};
Listing:  CMacLockDoc.c

/*****
 *
 * FILE:CMacLockDoc.c
 * Programmer: Mark Bykerk Kauffman
 * Date:1/91
 * Purpose:
 * Document methods for MacLock.
 * PARENTCLASS = CStarterDoc
 *
 *****/
 
#include <Global.h>
#include <Commands.h>
#include <CDesktop.h>
#include <CScrollPane.h>
#include "CMacLockPane.h"  
#include "CMacLockDoc.h"

/* Global Variables for objects of this class.     */
extern  CDesktop *gDesktop; 

/* Class Constants */
#define WINDMacLock500    /* Resource ID for the MacLock window. 
 */

/* METHOD IMPLEMENTATIONS */

/*****
 * IMacLockDoc
 *
 * MacLockDoc's initialization method.
 *
 *****/
void CMacLockDoc::IMacLockDoc(CBureaucrat *aSupervisor, Boolean printable)
{
 CDocument::IDocument(aSupervisor, printable);
}

/*****
 * BuildWindow
 *
 *  The NewFile() and OpenFile() in the MacLockDoc's
 * parent class use this method to create a window.
 * Because MacLock doesn't do anything with files,
 * NewFile and OpenFile methods do not need to be
 * defined for MacLock.  MacLock's window is unique to
 * MacLock so BuildWindow does need to be defined.
 *
 *****/
void CMacLockDoc::BuildWindow (Handle theData)
{
 CScrollPane*theScrollPane;
 CMacLockPane  *theMainPane;

 itsWindow = new(CWindow);
 itsWindow->IWindow(WINDMacLock, FALSE, gDesktop, this);

 theScrollPane = new(CScrollPane);
 
 /* Initialize theScrollPane without scroll bars
   or size box. */
 theScrollPane->IScrollPane(itsWindow, this, 10, 10, 0,
   0, sizELASTIC, sizELASTIC,
 FALSE, FALSE, FALSE);

 theScrollPane->FitToEnclFrame(TRUE, TRUE);

 theMainPane = new(CMacLockPane);
 itsMainPane = theMainPane;
 itsGopher = theMainPane;

 theMainPane->IMacLockPane(theScrollPane, this, 0, 0,
  0, 0, sizELASTIC, sizELASTIC);
 theMainPane->FitToEnclosure(TRUE, TRUE);

 theScrollPane->InstallPanorama(theMainPane);
}
Listing:  CAboutMacLock.h

/*****
 *
 * FILE:CAboutMacLock.h
 * Programmer: Mark Bykerk Kauffman
 * Date:1/91
 * Purpose:
 * Interface for CAboutMacLock.  I took the
 * AboutBox class from the ArtClass folder and
 * simplified it for this application.  I've used
 * the same method names Symantec used, but the methods
 * are completely specific for MacLock because the
 * AboutBox class from Symantec is not a generic about
 * box.  It is a class unique to ArtClass.  
 * 
 *****/
 
#define _H_CAboutMacLock.h

/* Parent class. */
#include <CDirector.h>    

struct CAboutMacLock : CDirector { 
/* Instance Variables */
 PicHandleaboutscreen;
 
/* Methods */
 void   IAboutMacLock(CBureaucrat *itsSupervisor);
 void   Dispose(void);  
 void   Display(void);
};
Listing:  CAboutMacLock.c

/*****
 *
 * FILE:CAboutMacLock.c
 * Programmer: Mark Bykerk Kauffman
 * Date:1/91
 * Purpose: 
 *  The AboutMacLock Class is used to create one object 
 *  which acts as an about box for MacLock.  It displays  
 *  some information in awindow and waits for the user 
 *  to press a key or click the mouse.
 * 
 * PARENTCLASS = CDirector
 *
 *****/

#include <Global.h>
#include <OSChecks.h>
#include <CDesktop.h>
#include <CDecorator.h>
#include <CColorWindow.h>
#include <CPicture.h>
#include "CAboutMacLock.h"

/* Global Variables for objects of this class.     */
extern CDesktop  *gDesktop; 
extern CDecorator*gDecorator; 

/* Class Constants */
#define WIND_ABOUT 2000
#define Plain    0        

/* METHOD IMPLEMENTATIONS */
/******
 * IAboutMacLock
 *
 * Initialize an AboutMacLock object.
 ******/
void  CAboutMacLock::IAboutMacLock(
 CBureaucrat*itsSupervisor)
{
 CDirector::IDirector(itsSupervisor);
 
 itsWindow = new(CWindow);
 itsWindow->IWindow(WIND_ABOUT, TRUE, gDesktop, this);
 
 gDecorator->CenterWindow(itsWindow);  
 
 Display();
}

/*****
 * Dispose 
 *
 * Release all of AboutMacLock's resourses. There's 
 *      only one.
 *****/
void  CAboutMacLock::Dispose()
{
 ReleaseResource(aboutscreen);
 inherited::Dispose();  
}

/*****
 * Display
 *
 * Display the AboutMacLock box.
 *****/
 /*
  * Wait for a key press or mouse click.
  */
 static Boolean  WaitForUserEvent()
 {
 EventRecordtheEvent;

 while (TRUE) {
 GetNextEvent(everyEvent,&theEvent);
 switch (theEvent.what)
 {
 case keyDown:
 return(TRUE);
 break;
 case mouseDown:
 return(TRUE);
 break; 
 }
 }
 }

void  CAboutMacLock::Display()
{
 
 itsWindow->Select();
 itsWindow->Prepare();
 SetOrigin(-12, -12);
 
 TextSize(14);
 MoveTo(10,20);
 DrawString("\pI put many hours of work into this program, it is NOT");
 MoveTo(10,40);
 DrawString("\pFREE.  This is a ONE DOLLAR SHAREWARE PROGRAM.");
 MoveTo(10,60);
 DrawString("\pIf you find this program useful, please take the time");
 MoveTo(10,80);
 DrawString("\pto put ONE DOLLAR in an envelope and send it to...");
 MoveTo(10,100);
 TextFace(bold);
 MoveTo(10,120);
 DrawString("\p      Mark Kauffman");
 MoveTo(10,140);
 DrawString("\p      254 E. 7th Ave.");
 MoveTo(10,160);
 DrawString("\p      Chico, CA 95926");
 TextSize(10);
 TextFace(Plain);
 MoveTo(10,190);
 DrawString("\pINSTRUCTIONS:");
 MoveTo(10,210);
 DrawString("\pUse command-p or the MacLock Menu to display the ");
 MoveTo(10,220);
 DrawString("\pChange Passowrd Dialog.");
 MoveTo(10,240);
 DrawString("\pPress the LOCK button to completly lock your system");
 MoveTo(10,250);
 DrawString("\puntil the password is typed in followed by the ");
 MoveTo(10,260);
 DrawString("\pReturn key.");
 WaitForUserEvent();    /* Wait for a key press or mouse click.*/
}
Listing:  CMacLockApp.c

/*****
 *
 * FILE:  CMacLockApp.c
 * Programmer:   Mark Bykerk Kauffman
 * Date:1/91
 * Purpose: 
 * Application methods for CMacLockApp.
 *
 * PARENTCLASS = CStarterApp
 *****/
 
#include "Commands.h"/* So cmdOpen and cmdAbout work           
 inDoCommand.*/
#include "MacLockCmds.h"  /* This applications commands        
 for DoCommand */
#include "CMacLockApp.h"  
#include "CMacLockDoc.h"  
#include <CFWDesktop.h>   /*  Floating Window Desktop. */
#include "CBartender.h"   
#include "CAboutMacLock.h"
#include "CPassword.h"

/* Global Variables for objects of this class.     */
extern  CBartender *gBartender;
extern CDesktop  *gDesktop; /* The visible Desktop */
extern CBureaucrat *gGopher;/* First in line to get commands */
CPassword *gThePassword;

/* METHOD IMPLEMENTATIONS */
/*****
 * IMacLockApp
 *
 * Initialize the application.  Create an object,
 *  gThePassword, which is global to the application and
 *  initialize it.  Call the parent class
 *  initialization method.
 *****/
void CMacLockApp::IMacLockApp(void)
{
 gThePassword = new(CPassword);
 gThePassword->IPassword();
 CStarterApp::IStarterApp();
}

/*****
 * StartUpAction
 *
 * Start the application by asking for money.
 *****/
void  CMacLockApp::StartUpAction(short numPreloads)
{
 gGopher->DoCommand(cmdAbout);
 inherited::StartUpAction(numPreloads);
}

/*****
 * MakeDesktop
 *
 * Use the Desktop subclass which supports floating
 *  windows.  This was absolutly necessary to make the
 *  AboutMacLock work properly.Without floating windows,
 *  the lock window was deselected every time the
 *  AboutMacLock was called up.
 *****/
void  CMacLockApp::MakeDesktop()
{
 gDesktop = new(CFWDesktop);
 ((CFWDesktop*)gDesktop)->IFWDesktop(this);
}
 
/*****
* UpdateMenus 
* 
*  Menu management.
*****/
void  CMacLockApp::UpdateMenus()
{
 inherited::UpdateMenus();
 gBartender->EnableCmd(cmdPassword);
}

/*****
 * DoCommand
 *
 * Commands 1-1023 are reserved.  cmdPassword is
 * defined in MacLockCmds.h, cmdOpen and cmdAbout are
 * defined in Commands.h.  The inherited method 
 * should always be called as the default of your
 * switch statement so that all standard commands that
 * you don't handle will be taken care of.
 *****/
void CMacLockApp::DoCommand(long theCommand)
{
 int    numberofitems;
 CAboutMacLock *theAboutMacLock;
 CWindow*oldWindow;
 
 switch (theCommand) {
 /* These are the commands that MacLock responds to. */
 case cmdOpen:
 /* Override the inherited response to cmdOpen.  Check
 how many directors the application has by sending a
 GetNumItems message to itsDirectors.  If there are
   two, then the application already has a MacLock
      window on the screen and we don't want to display
 another.  Remove the if statement and you will 
 getanother MacLock window every time you do an Open 
 from the menu or press command-O.*/

 numberofitems = itsDirectors->GetNumItems();
 if (numberofitems < 2)      
 CreateDocument();  
 break;
    
 case cmdPassword:
 gThePassword->ChangePassword();
 break;
 
 case cmdAbout:
 theAboutMacLock = new(CAboutMacLock);
 theAboutMacLock->IAboutMacLock(this);
 theAboutMacLock->Dispose();
 FlushEvents(mDownMask+mUpMask+keyDownMask+
 keyUpMask+autoKeyMask, 0);
 break;

 /* Call the inherited DoCommand here.*/
 default: inherited::DoCommand(theCommand);
 break;
 }
}

/*****
 * CreateDocument
 *
 * Create the unique MacLock Document.  Send it a
 * newFile message so that
 * it opens a new MacLock window.
 *****/
void CMacLockApp::CreateDocument()
{
 CMacLockDoc*theDocument;
 
 theDocument = new(CMacLockDoc);   
 theDocument->IMacLockDoc(this, TRUE);
 theDocument->NewFile();
}

/*****
 * OpenDocument
 *
 * The user chose Open  from the File menu.
 *  Create a new Maclock document
 *  (if one hasn't already been created).
 *****/
void CMacLockApp::OpenDocument(SFReply *macSFReply)
{
 CMacLockDoc*theDocument;
 
 theDocument = new(CMacLockDoc);
 
  /*  Send your document an initialization
 message. The first argument is the
 supervisor (the application). The second
   argument is TRUE if the document is printable.*/
 
 theDocument->IMacLockDoc(this, TRUE);

 /*Send the document an OpenFile() message.
 The document will open a window, open
 the file specified in the macSFReply record,
 and display it in its window.*/
 
 theDocument->OpenFile(macSFReply);
 }
Listing:  MacLock.c

/*****
 *
 * FILE:MacLock.c
 * Programmer: Mark Bykerk Kauffman
 * Date:1/90
 * Purpose:
 * MacLock main. 
 *
 *****/
 
#include "CMacLockApp.h"

extern  CApplication *gApplication;

void main()
{
 gApplication = new(CMacLockApp);
 ((CMacLockApp *)gApplication)->IMacLockApp();
 gApplication->Run();
 gApplication->Exit();
}

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

coconutBattery 3.9.14 - Displays info ab...
With coconutBattery you're always aware of your current battery health. It shows you live information about your battery such as how often it was charged and how is the current maximum capacity in... Read more
Keynote 13.2 - Apple's presentation...
Easily create gorgeous presentations with the all-new Keynote, featuring powerful yet easy-to-use tools and dazzling effects that will make you a very hard act to follow. The Theme Chooser lets you... Read more
Apple Pages 13.2 - Apple's word pro...
Apple Pages is a powerful word processor that gives you everything you need to create documents that look beautiful. And read beautifully. It lets you work seamlessly between Mac and iOS devices, and... Read more
Numbers 13.2 - Apple's spreadsheet...
With Apple Numbers, sophisticated spreadsheets are just the start. The whole sheet is your canvas. Just add dramatic interactive charts, tables, and images that paint a revealing picture of your data... Read more
Ableton Live 11.3.11 - Record music usin...
Ableton Live lets you create and record music on your Mac. Use digital instruments, pre-recorded sounds, and sampled loops to arrange, produce, and perform your music like never before. Ableton Live... Read more
Affinity Photo 2.2.0 - Digital editing f...
Affinity Photo - redefines the boundaries for professional photo editing software for the Mac. With a meticulous focus on workflow it offers sophisticated tools for enhancing, editing and retouching... Read more
SpamSieve 3.0 - Robust spam filter for m...
SpamSieve is a robust spam filter for major email clients that uses powerful Bayesian spam filtering. SpamSieve understands what your spam looks like in order to block it all, but also learns what... Read more
WhatsApp 2.2338.12 - Desktop client for...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
Fantastical 3.8.2 - Create calendar even...
Fantastical is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event details... Read more
iShowU Instant 1.4.14 - Full-featured sc...
iShowU Instant gives you real-time screen recording like you've never seen before! It is the fastest, most feature-filled real-time screen capture tool from shinywhitebox yet. All of the features you... Read more

Latest Forum Discussions

See All

The iPhone 15 Episode – The TouchArcade...
After a 3 week hiatus The TouchArcade Show returns with another action-packed episode! Well, maybe not so much “action-packed" as it is “packed with talk about the iPhone 15 Pro". Eli, being in a time zone 3 hours ahead of me, as well as being smart... | Read more »
TouchArcade Game of the Week: ‘DERE Veng...
Developer Appsir Games have been putting out genre-defying titles on mobile (and other platforms) for a number of years now, and this week marks the release of their magnum opus DERE Vengeance which has been many years in the making. In fact, if the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 22nd, 2023. I’ve had a good night’s sleep, and though my body aches down to the last bit of sinew and meat, I’m at least thinking straight again. We’ve got a lot to look at... | Read more »
TGS 2023: Level-5 Celebrates 25 Years Wi...
Back when I first started covering the Tokyo Game Show for TouchArcade, prolific RPG producer Level-5 could always be counted on for a fairly big booth with a blend of mobile and console games on offer. At recent shows, the company’s presence has... | Read more »
TGS 2023: ‘Final Fantasy’ & ‘Dragon...
Square Enix usually has one of the bigger, more attention-grabbing booths at the Tokyo Game Show, and this year was no different in that sense. The line-ups to play pretty much anything there were among the lengthiest of the show, and there were... | Read more »
Valve Says To Not Expect a Faster Steam...
With the big 20% off discount for the Steam Deck available to celebrate Steam’s 20th anniversary, Valve had a good presence at TGS 2023 with interviews and more. | Read more »
‘Honkai Impact 3rd Part 2’ Revealed at T...
At TGS 2023, HoYoverse had a big presence with new trailers for the usual suspects, but I didn’t expect a big announcement for Honkai Impact 3rd (Free). | Read more »
‘Junkworld’ Is Out Now As This Week’s Ne...
Epic post-apocalyptic tower-defense experience Junkworld () from Ironhide Games is out now on Apple Arcade worldwide. We’ve been covering it for a while now, and even through its soft launches before, but it has returned as an Apple Arcade... | Read more »
Motorsport legends NASCAR announce an up...
NASCAR often gets a bad reputation outside of America, but there is a certain charm to it with its close side-by-side action and its focus on pure speed, but it never managed to really massively break out internationally. Now, there's a chance... | Read more »
Skullgirls Mobile Version 6.0 Update Rel...
I’ve been covering Marie’s upcoming release from Hidden Variable in Skullgirls Mobile (Free) for a while now across the announcement, gameplay | Read more »

Price Scanner via MacPrices.net

New low price: 13″ M2 MacBook Pro for $1049,...
Amazon has the Space Gray 13″ MacBook Pro with an Apple M2 CPU and 256GB of storage in stock and on sale today for $250 off MSRP. Their price is the lowest we’ve seen for this configuration from any... Read more
Apple AirPods 2 with USB-C now in stock and o...
Amazon has Apple’s 2023 AirPods Pro with USB-C now in stock and on sale for $199.99 including free shipping. Their price is $50 off MSRP, and it’s currently the lowest price available for new AirPods... Read more
New low prices: Apple’s 15″ M2 MacBook Airs w...
Amazon has 15″ MacBook Airs with M2 CPUs and 512GB of storage in stock and on sale for $1249 shipped. That’s $250 off Apple’s MSRP, and it’s the lowest price available for these M2-powered MacBook... Read more
New low price: Clearance 16″ Apple MacBook Pr...
B&H Photo has clearance 16″ M1 Max MacBook Pros, 10-core CPU/32-core GPU/1TB SSD/Space Gray or Silver, in stock today for $2399 including free 1-2 day delivery to most US addresses. Their price... Read more
Switch to Red Pocket Mobile and get a new iPh...
Red Pocket Mobile has new Apple iPhone 15 and 15 Pro models on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide service using all the major... Read more
Apple continues to offer a $350 discount on 2...
Apple has Studio Display models available in their Certified Refurbished store for up to $350 off MSRP. Each display comes with Apple’s one-year warranty, with new glass and a case, and ships free.... Read more
Apple’s 16-inch MacBook Pros with M2 Pro CPUs...
Amazon is offering a $250 discount on new Apple 16-inch M2 Pro MacBook Pros for a limited time. Their prices are currently the lowest available for these models from any Apple retailer: – 16″ MacBook... Read more
Closeout Sale: Apple Watch Ultra with Green A...
Adorama haș the Apple Watch Ultra with a Green Alpine Loop on clearance sale for $699 including free shipping. Their price is $100 off original MSRP, and it’s the lowest price we’ve seen for an Apple... Read more
Use this promo code at Verizon to take $150 o...
Verizon is offering a $150 discount on cellular-capable Apple Watch Series 9 and Ultra 2 models for a limited time. Use code WATCH150 at checkout to take advantage of this offer. The fine print: “Up... Read more
New low price: Apple’s 10th generation iPads...
B&H Photo has the 10th generation 64GB WiFi iPad (Blue and Silver colors) in stock and on sale for $379 for a limited time. B&H’s price is $70 off Apple’s MSRP, and it’s the lowest price... Read more

Jobs Board

Optometrist- *Apple* Valley, CA- Target Opt...
Optometrist- Apple Valley, CA- Target Optical Date: Sep 23, 2023 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 796045 At Target Read more
Senior *Apple* iOS CNO Developer (Onsite) -...
…Offense and Defense Experts (CODEX) is in need of smart, motivated and self-driven Apple iOS CNO Developers to join our team to solve real-time cyber challenges. Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Child Care Teacher - Glenda Drive/ *Apple* V...
Child Care Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Share on Facebook Apply Read more
Machine Operator 4 - *Apple* 2nd Shift - Bon...
Machine Operator 4 - Apple 2nd ShiftApply now " Apply now + Start apply with LinkedIn + Apply Now Start + Please wait Date:Sep 22, 2023 Location: Swedesboro, NJ, US, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.