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
$99.18
Apple Inc.
-1.57
MSFT
$45.90
Microsoft Corpora
-0.46
GOOG
$568.27
Google Inc.
-9.09

MacTech Search:
Community Search:

Software Updates via MacUpdate

Cocktail Family License (5 Macs) 7.6.1 -...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
Cocktail 8.0 Beta 2 - General maintenanc...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
QuickBooks 2015 16.0.0.1352 R1 - Financi...
QuickBooks 2015 helps you manage your business easily and efficiently. Organize your finances all in one place, track money going in and out of your business, and spot areas where you can save.... Read more
Mac DVDRipper Pro 5.0.1 - Copy, backup,...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
Apple OS X bash Update 1.0 - Fix for sec...
The OS X bash Update fixes a security flaw in the bash UNIX shell on OS X 10.9.5 (also on OS X 10.8 and 10.7 [see Related Links below]). OS X 10.9.5 or later Downloads for OS X 10.8 and OS X 10.7 in... Read more
SyncTwoFolders 2.0.5 - Syncs two user-sp...
SyncTwoFolders simply synchronizes two folders. It supports synchronization across mounted network drives and it is a possibility to run a simulation showing in a log what will be done. Please visit... Read more
FinderPop 2.5.7 - Classic Mac utility, n...
FinderPop is a Universal preference pane that extends OS X's contextual menus using a FinderPop Items folder much as the Apple Menu Items folder used to do for the Apple menu. It has other features... Read more
VueScan 9.4.45 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
LibreOffice 4.3.2.2 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
calibre 2.4 - Complete e-library managem...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more

Latest Forum Discussions

See All

iKeywi - Customizable 5-Row Keyboard (U...
iKeywi - Customizable 5-Row Keyboard 1.0 Device: iOS Universal Category: Utilities Price: $.99, Version: 1.0 (iTunes) Description: Want to add an extra row to your iPhone/iPad? One of the most popular keyboard extension in iOS... | Read more »
Manage Your Cloud – Wunderlist Now Suppo...
Manage Your Cloud – Wunderlist Now Supports Dropbox Posted by Jessica Fisher on October 1st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Nexticy Review
Nexticy Review By Jennifer Allen on October 1st, 2014 Our Rating: :: IDEAL FORM CREATIONiPad Only App - Designed for the iPad Nexticy allows you to make your own forms for research purposes or to organize your business better. It’s... | Read more »
Tiny Troopers: Alliance Marches onto the...
Tiny Troopers: Alliance Marches onto the App Store Tomorrow Posted by Jessica Fisher on October 1st, 2014 [ permalink ] Tiny Troopers: Alliance, by Kukouri, is a | Read more »
HeroCraft Introduces Unlimited Sequel to...
HeroCraft Introduces Unlimited Sequel to WW2: Sandbox. Strategy & Tactics Posted by Jessica Fisher on October 1st, 2014 [ permalink ] | Read more »
RGB Express Review
RGB Express Review By Jennifer Allen on October 1st, 2014 Our Rating: :: DELIGHTFUL PUZZLINGUniversal App - Designed for iPhone and iPad Guide trucks along their delivery routes in RGB Express, a testing but charming puzzle game... | Read more »
The Sagas of Fire*Wolf (Games)
The Sagas of Fire*Wolf 1.0 Device: iOS Universal Category: Games Price: $9.99, Version: 1.0 (iTunes) Description: | Read more »
BuggyFun Review
BuggyFun Review By Amy Solomon on October 1st, 2014 Our Rating: iPad Only App - Designed for the iPad BuggyFun allows children to create their own tracks for bugs to interact with for a unique open-ended experience.   | Read more »
Fold the Adventure Review
Fold the Adventure Review By Jennifer Allen on October 1st, 2014 Our Rating: :: AWKWARD FOLDSUniversal App - Designed for iPhone and iPad Fold pieces of paper to create platforms for a princely rabbit in this puzzle game; something... | Read more »
WW2: Sandbox. Strategy & Tactics (G...
WW2: Sandbox. Strategy & Tactics 1.0.0 Device: iOS Universal Category: Games Price: $9.99, Version: 1.0.0 (iTunes) Description: ***NOTE: Compatible with iPhone 4s and up, iPad 2 and up - may not work properly on earlier devices... | Read more »

Price Scanner via MacPrices.net

Amazon offers 13-inch MacBook Air for $899, $...
Amazon.com has the 13″ 1.4GHz 128GB MacBook Air on sale for $100 off MSRP including free shipping: - 13″ 1.4GHz 128GB MacBook Air: $899.99 Read more
Apple resting On Its iPhone Laurels? – The ‘B...
Apple calls its new iPhone 6 and 6 Plus “The Biggest Advancements in iPhone History,” but does reality live up to the hype? “Seldom have so many waited so breathlessly for so little,” tweeted veteran... Read more
Roundup of Apple Mac and iPad Education disco...
Purchase a new Mac or iPad at The Apple Store for Education and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free,... Read more
Apple Boycotts German Magazine Computer Bild...
Apple has revoked its PR accreditation of Germany’s Computer Bild, Europe’s best-selling PC magazine, in reaction to Bild’s posting of a “#Bentgate” YouTube video. Axel Telzerow, editor in chief of... Read more
iPhone 6 & iPhone 6 Plus Available in Chi...
Apple has announced that iPhone 6 and iPhone 6 Plus will be available in China beginning Friday, October 17 from the Apple Online Store (http://www.apple.com), Apple’s retail stores, and an expansive... Read more
MacBook Airs on sale for $100 off MSRP, start...
Best Buy has the new 2014 MacBook Airs on sale for $100 off MSRP on their online store. Choose free home shipping or free local store pickup (if available). Prices valid for online orders only, in-... Read more
Apple Releases OS X Mavericks bash Update 1.0...
Apple has released a patch update for OS X Mavericks users to address the recently-detected “Shellshock” security bug in BSD UNIX’s bash shell. Apple says only a few Mac users who had manually... Read more
Pivotal Payments Ready for Apple Pay – FlexPo...
Pivotal Payments, a provider of merchant services and global payment processing solutions, has announced its proprietary FlexPoint platform will support credit and debit transactions through Apple’s... Read more
iStabilizer Announces Tabarm — First Friction...
iStabilizer, a specialist in universal lightweight compact tripods, steady cams, dollies, mounts, and remotes for smartphones, tablets, and cameras, announced today the iStabilizer tabArm, the first... Read more
IStabilizer Flex Smartphone Tripod Wins Usa T...
iStabilizer, a specialist in universal lightweight compact tripods, steady cams, and other products for smartphones, tablets, and cameras, has announced today that its iStabilizer Flex smartphone... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*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
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.