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();
}

 
AAPL
$97.67
Apple Inc.
+0.64
MSFT
$44.50
Microsoft Corpora
+0.10
GOOG
$589.02
Google Inc.
-4.33

MacTech Search:
Community Search:

Software Updates via MacUpdate

TinkerTool 5.3 - Expanded preference set...
TinkerTool is an application that gives you access to additional preference settings Apple has built into Mac OS X. This allows to activate hidden features in the operating system and in some of the... Read more
Audio Hijack Pro 2.11.0 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Intermission 1.1.1 - Pause and rewind li...
Intermission allows you to pause and rewind live audio from any application on your Mac. Intermission will buffer up to 3 hours of audio, allowing users to skip through any assortment of audio... Read more
Autopano Giga 3.6 - Stitch multiple imag...
Autopano Giga allows you to stitch 2, 20, or 2,000 images. Version 3.0 integrates impressive new features that will definitely make you adopt Autopano Pro or Autopano Giga: Choose between 9... Read more
Airfoil 4.8.7 - Send audio from any app...
Airfoil allows you to send any audio to AirPort Express units, Apple TVs, and even other Macs and PCs, all in sync! It's your audio - everywhere. With Airfoil you can take audio from any... Read more
Microsoft Remote Desktop 8.0.8 - Connect...
With Microsoft Remote Desktop, you can connect to a remote PC and your work resources from almost anywhere. Experience the power of Windows with RemoteFX in a Remote Desktop client designed to help... Read more
xACT 2.30 - Audio compression toolkit. (...
xACT stands for X Aaudio Compression Toolkit, an application that encodes and decodes FLAC, SHN, Monkey’s Audio, TTA, Wavpack, and Apple Lossless files. It also can encode these formats to MP3, AAC... Read more
Firefox 31.0 - Fast, safe Web browser. (...
Firefox for Mac offers a fast, safe Web browsing experience. Browse quickly, securely, and effortlessly. With its industry-leading features, Firefox is the choice of Web development professionals... Read more
Little Snitch 3.3.3 - Alerts you to outg...
Little Snitch gives you control over your private outgoing data. Track background activityAs soon as your computer connects to the Internet, applications often have permission to send any... Read more
Thunderbird 31.0 - Email client from Moz...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more

Latest Forum Discussions

See All

Jacob Jones and the Bigfoot Mystery : Ep...
Jacob Jones and the Bigfoot Mystery : Episode 2 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Jacob Jones is back in Episode 2 of one of Apples 'Best of 2013' games and an App Store... | Read more »
New Trailer For Outcast Odyssey, A New K...
New Trailer For Outcast Odyssey, A New Kind of Card Battler Posted by Jennifer Allen on July 25th, 2014 [ permalink ] Out this Fall is a new kind of card battle game: Outcast Odyssey. | Read more »
Garfield: Survival of the Fattest Coming...
Garfield: Survival of the Fattest Coming to iOS this Fall Posted by Jennifer Allen on July 25th, 2014 [ permalink ] Who loves lasagna? Me. Also everyone’s favorite grumpy fat cat, Garfield. | Read more »
Happy Flock Review
Happy Flock Review By Andrew Fisher on July 25th, 2014 Our Rating: :: HERD IT ALL BEFOREUniversal App - Designed for iPhone and iPad Underneath the gloss of Happy Flock’s visuals is a game of very little substance. It’s cute, but... | Read more »
Square Register Updates Adds Offline Pay...
Square Register Updates Adds Offline Payments Posted by Ellis Spice on July 25th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Looking For Group – Hearthstone’s Curse...
For the first time since its release (which has thankfully been a much shorter window for iPad players than their PC counterparts), Blizzard’s wildly successful Hearthstone: Heroes of Warcraft CCG is sporting some brand new content: the single... | Read more »
Poptile Review
Poptile Review By Jennifer Allen on July 25th, 2014 Our Rating: :: SIMPLY FUNUniversal App - Designed for iPhone and iPad Simple yet a little bit glorious, Poptile is a satisfying entertaining puzzle game with oodles of the ‘one... | Read more »
Modern Combat 5: Blackout Review
Modern Combat 5: Blackout Review By Brittany Vincent on July 25th, 2014 Our Rating: :: LESS QQ, MORE PEW PEWUniversal App - Designed for iPhone and iPad The fifth entry into the blockbuster Modern Combat series is what mobile... | Read more »
Watch and Share Mobile Gameplay Videos W...
Watch and Share Mobile Gameplay Videos With Kamcord Posted by Jennifer Allen on July 25th, 2014 [ permalink ] iPhone App - Designed for the iPhone, compatible with the iPad | Read more »
THE KING OF FIGHTERS '98 (Games)
THE KING OF FIGHTERS '98 1.0 Device: iOS Universal Category: Games Price: $3.99, Version: 1.0 (iTunes) Description: Series’ masterpiece “KOF ’98” finally joins the battle on iPhone! FEATURES:■ The best game balance in the “KOF”... | Read more »

Price Scanner via MacPrices.net

iMacs on sale for $150 off MSRP, $250 off for...
Best Buy has iMacs on sale for up to $160 off MSRP for a limited time. Choose free home shipping or free instant local store pickup (if available). Prices are valid for online orders only, in-store... Read more
Mac minis on sale for $100 off MSRP, starting...
Best Buy has Mac minis on sale for $100 off MSRP. Choose free shipping or free instant local store pickup. Prices are for online orders only, in-store prices may vary: 2.5GHz Mac mini: $499.99 2.3GHz... Read more
Global Tablet Market Grows 11% in Q2/14 Notwi...
Worldwide tablet sales grew 11.0 percent year over year in the second quarter of 2014, with shipments reaching 49.3 million units according to preliminary data from the International Data Corporation... Read more
New iPhone 6 Models to Have Staggered Release...
Digitimes’ Cage Chao and Steve Shen report that according to unnamed sources in Apple’s upstream iPhone supply chain, the new 5.5-inch iPhone will be released several months later than the new 4.7-... Read more
New iOS App Helps People Feel Good About thei...
Mobile shoppers looking for big savings at their favorite stores can turn to the Goodshop app, a new iOS app with the latest coupons and deals at more than 5,000 online stores. In addition to being a... Read more
Save on 5th generation refurbished iPod touch...
The Apple Store has Apple Certified Refurbished 5th generation iPod touches available starting at $149. Apple’s one-year warranty is included with each model, and shipping is free. Many, but not all... Read more
What Should Apple’s Next MacBook Priority Be;...
Stabley Times’ Phil Moore says that after expanding its iMac lineup with a new low end model, Apple’s next Mac hardware decision will be how it wants to approach expanding its MacBook lineup as well... Read more
ArtRage For iPhone Painting App Free During C...
ArtRage for iPhone is currently being offered for free (regularly $1.99) during Comic-Con San Diego #SDCC, July 24-27, in celebration of the upcoming ArtRage 4.5 and other 64-bit versions of the... Read more
With The Apple/IBM Alliance, Is The iPad Now...
Almost since the iPad was rolled out in 2010, and especially after Apple made a 128 GB storage configuration available in 2012, there’s been debate over whether the iPad is a serious tool for... Read more
MacBook Airs on sale starting at $799, free s...
B&H Photo has the new 2014 MacBook Airs on sale for up to $100 off MSRP for a limited time. Shipping is free, and B&H charges NY sales tax only. They also include free copies of Parallels... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Sr. Project Manager for *Apple* Campus 2 -...
…the design and construction of one building or building components of the New Apple Campus located in Cupertino, CA. They will provide project management oversight for Read more
WW Sales Program Manager, *Apple* Online St...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.