TweetFollow Us on Twitter

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

MacLock

By Mark Bykerk-Kauffman, Chico, CA

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

MacLock 1.0: A Complete Object-Oriented Application

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

Origins

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

One-Dollar Shareware

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

Dodging The Lawyers

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

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

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

Thinking OOP

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

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

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

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

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

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

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

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

Arrange the Folders Used by MacLock

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

Build the MacLock Project

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

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

Modify the Resource Table

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

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

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

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

Figure 1.

Figure 2.

Figure 3

Figure 4.

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

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

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

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

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

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

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

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

Figure 5.

Figure 6.

Figure 7.

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

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

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

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

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

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

Figure 8.

Figure 9.

Figure 10.

Figure 11.

Figure 12.

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

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

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

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

Type in the MacLock Source Code

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

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

Figure 13.

Figure 14.

Figure 15.

Figure 16.

Figure 17.

Possibilities!

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

References

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

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

Listing:  CMacLockApp.h

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

#define _H_CMacLockApp    

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

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

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

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

#define cmdPassword2048   
Listing:  CPassword.h

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

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

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

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

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

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

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

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

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

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

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

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

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

#include <CButton.h>

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

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

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

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

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

/* METHOD IMPLEMENTATIONS */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* METHOD IMPLEMENTATIONS */

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

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

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

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

 theScrollPane->FitToEnclFrame(TRUE, TRUE);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

extern  CApplication *gApplication;

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

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more
New promo at Visible: Buy a new iPhone, get $...
Switch to Visible, and buy a new iPhone, and Visible will take $10 off their monthly Visible+ service for 24 months. Visible+ is normally $45 per month. With this promotion, the cost of Visible+ is... Read more
B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for $100 off Apple’s new MSRP, only $899. Free 1-2 day delivery is available to most US addresses. Their... Read more
Take advantage of Apple’s steep discounts on...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.