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
$517.96
Apple Inc.
-3.72
MSFT
$39.75
Microsoft Corpora
+0.57
GOOG
$536.44
Google Inc.
+3.92

MacTech Search:
Community Search:

Software Updates via MacUpdate

Starcraft II: Wings of Liberty 1.1.1.180...
Download the patch by launching the Starcraft II game and downloading it through the Battle.net connection within the app. Starcraft II: Wings of Liberty is a strategy game played in real-time. You... Read more
Sibelius 7.5.0 - Music notation solution...
Sibelius is the world's best-selling music notation software for Mac. It is as intuitive to use as a pen, yet so powerful that it does most things in less than the blink of an eye. The demo includes... Read more
Typinator 5.9 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more
MYStuff Pro 2.0.16 - Create inventories...
MYStuff Pro is the most flexible way to create detail-rich inventories for your home or small business. Add items to MYStuff by dragging and dropping existing information, uploading new images, or... Read more
TurboTax 2013.r17.002 - Manage your 2013...
TurboTax guides you through your tax return step by step, does all the calculations, and checks your return for errors and overlooked deductions. It lets you file your return electronically to get... Read more
TrailRunner 3.8.769 - Route planning for...
Note: While the software is classified as freeware, it is actually donationware. Please consider making a donation to help support development. TrailRunner is the perfect companion for runners,... Read more
Flavours 1.1.10 - Create and apply theme...
Flavours is a Mac application that allow users to create, apply and share beautifully designed themes. Classy Give your Mac a gorgeous new look by applying delicious themes! Easy Unleash your... Read more
Spotify 0.9.8.296. - Stream music, creat...
Spotify is a streaming music service that gives you on-demand access to millions of songs. Whether you like driving rock, silky R&B, or grandiose classical music, Spotify's massive catalogue... Read more
SlingPlayer Plugin 3.3.20.475 - 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
S.M.A.R.T. for USB and FireWire Drives 0...
S.M.A.R.T. for USB and FireWire Drives is a kernel driver for OS X external usb or firewire drives. It extends the standard driver behaviour by providing access to drive smart data. The interface to... Read more

Latest Forum Discussions

See All

148Apps Live on Twitch: Pivvot’s Looper...
On our latest Twitch stream, we’ll be playing a pair of minimalist arcade games, one that just got a big content update in Pivvot, and another that was inspired by it in 15 Coins. Whitaker Trebella, creator of Pivvot, will discuss the new modes... | Read more »
Word Cubes Review
Word Cubes Review By Jordan Minor on April 15th, 2014 Our Rating: :: SQUARESVILLEUniversal App - Designed for iPhone and iPad Word Cubes is fine, but it is barely any different from any other word game.   | Read more »
PAX East 2014 – Desert Fox: The Battle o...
PAX East 2014 – Desert Fox: The Battle of El Alamein is Coming to iOS Soon Posted by Rob Rich on April 15th, 2014 [ permalink ] Shenandoah Studio has become one of the go-to developers for war games on iOS, with | Read more »
Tank of Tanks Review
Tank of Tanks Review By Carter Dotson on April 15th, 2014 Our Rating: :: TANKS A LOT!iPad Only App - Designed for the iPad This multiplayer game played on a single iPad is simple, chaotic fun.   | Read more »
PAX East 2014 – Dungeon of the Endless J...
PAX East 2014 – Dungeon of the Endless Just Might Have a Shot at an iPad Release Posted by Rob Rich on April 15th, 2014 [ permalink ] I think it’s fair to say that | Read more »
SideSwype Review
SideSwype Review By Carter Dotson on April 15th, 2014 Our Rating: :: ON YOUR SIDEUniversal App - Designed for iPhone and iPad SideSwype is a puzzler that takes inspiration from Threes, but becomes its own incredibly fun game.   | Read more »
PAX East 2014 – Bigfoot Hunter Invites P...
PAX East 2014 – Bigfoot Hunter Invites Players on a Wild and Wooly Photo Safari Posted by Rob Rich on April 15th, 2014 [ permalink ] Yeti. Sasquatch. Wendigo. | Read more »
Dungeon Quest Review
Dungeon Quest Review By Cata Modorcea on April 15th, 2014 Our Rating: :: NO STORY, BUT GOOD FUNUniversal App - Designed for iPhone and iPad Dungeon Quest does a lot of things right, but ultimately forgets about one of the core... | Read more »
Tempo AI and Speek Join Forces to “Kill...
Tempo AI and Speek Join Forces to “Kill the Conference Call PIN” Posted by Rob Rich on April 15th, 2014 [ permalink ] Today Tempo AI, makers of Tempo Smart Calendar, and | Read more »
Fighting Fantasy: Starship Traveller Rev...
Fighting Fantasy: Starship Traveller Review By Jennifer Allen on April 15th, 2014 Our Rating: :: A SIGNIFICANT VOYAGEUniversal App - Designed for iPhone and iPad Continuing the release of Fighting Fantasy titles, Starship Traveller... | Read more »

Price Scanner via MacPrices.net

Save $50 on Mac mini Server
B&H Photo has the 2012 Mac mini Server on sale for $949 including free shipping plus NY sales tax only. Their price is $50 off MSRP. Read more
PhatWare’s “Ultimate Writing App For iOS” Ren...
PhatWare Corp. has announced it has renamed its new WritePro word processing app for iPhone and iPad: WritePad Pro. The decision to change the app’s name to leverages the strong brand awareness and... Read more
Full Resolution Photo Editor Tint Mint 1.0 Re...
California based independent developer, Jeffrey Sun, creator of the iOS app Modern Editor, has released Tint Mint, a new photography app for editing enthusiasts. The app costs a dollar, and it packs... Read more
16GB iPad mini (Apple refurbished) available...
The Apple Store has refurbished 1st generation 16GB iPad minis available for $249 including free shipping. Both black and white models are available. Read more
Save $120 on the 27-inch 3.2GHz Haswell iMac
B&H Photo has the 27″ 3.2GHz iMac on sale for $1679.99 including free shipping plus NY sales tax only. Their price is about $120 off MSRP. Read more
Using a Mac Doesn’t Eliminate The Heartbleed...
Low End Mac’s Dan Knight notes that any time you visit a website with an https: prefix or see that secure lock icon on your browser, some type of security software is busy trying to protect your data... Read more
AirPrint Basics Tutorial Posted
A new Apple Knowledge Base article helps get you started using AirPrint, the Apple protocol that enables instant printing from iPad, iPhone, iPod touch, and Mac without the need to install drivers or... Read more
Speed Tips For Running LibreOffice On The Mac
LibreOffice is my favorite of several free, open-source application suites, and the one I have configured on my Mac as my default app for Word documents that one frequently has to deal with. It also... Read more
Snag a 15-inch Retina MacBook Pro for $115 of...
B&H Photo has 2013 15″ Retina MacBook Pros on sale for up to $115 off MSRP for a limited time. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.3GHz Retina MacBook Pro: $2489.99... Read more
MacBook Airs on sale for $50 to $100 off MSRP
Several resellers are offering $50-$100 discounts on 11″ and 13″ MacBook Airs today, including Amazon, Best Buy, B&H, and others. See the breakdown of deals on our MacBook Air Price Tracker,... Read more

Jobs Board

*Apple* Retail - Market Leader - Cincinnati...
…challenges of developing individuals, building teams, and affecting growth across Apple Stores. You demonstrate successful leadership ability - focusing on excellence Read more
*Apple* Retail - Manager - SoHo - Apple (Uni...
Job SummaryKeeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you're a master of them all. In the store's fast-paced, dynamic Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** Every day, business customers come to the Apple Store to discover what powerful, easy-to-use Apple products can do for them. As a Business Leader, Read more
Position Opening at *Apple* - Apple (United...
…challenges of developing individuals, building teams, and affecting growth across Apple Stores. You demonstrate successful leadership ability - focusing on excellence Read more
Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.