macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Building Mac Applications Using REALbasic 4.5 for Mac OS X
Pages: 1, 2, 3

Building Our Sample Application

Using the Windows editor, let's now drag and drop a few controls onto the default Window1, as shown below

Screen shot.
Building our simple text editor.

Take some time to explore the various properties associated with each control. If you are familiar with Visual Studio .NET, then you will feel really at home. For example, to make your window re-sizable, you check the GrowIcon property of the window. To anchor the controls to a window when it is re-sized, you have the options to anchor it against the left, right, top or bottom by checking the LockLeft, LockRight, LockTop or LockBottom properties respectively.



When you are done adding the controls to your window, it is time to do some coding. As you may have guessed it right, double-clicking on the controls brings up the Code Editor:

Screen shot.
The Code Editor.

On the left of the Code Editor you find the Browser containing the various grouping of items such as Controls, Events, etc. A Column Divider separates the Browser and the code area. For our sample application, the first set of codes that we need to write is to show the contextual menu when the user right-clicks on a selected piece of text:

Screen shot.
Displaying the contextual menu.

So, in the Code Editor, locate the EditField control and type in the following code under the MouseDown event:

Screen shot.
Invoking the contextual menu.

The IsCMMClick() function returns a true if the user clicks on a control while pressing the Control key. Essentially it is used to determine if a Contextual Menu should be displayed. If it does, display Contextual Menu 1:

Screen shot.
Displaying the contextual menu.

The above codes add in the Font and Color menu items to the ContextualMenu control. When the user clicks on one of the items in the contextual menu, it triggers the Action event:

Screen shot.
Determining which item has been selected in the contextual menu.

If the user selects the Font menu item, the second ContextualMenu will be displayed. If the user clicks on the Color item, the SelectColor() function will display the standard Color picker:

Screen shot.
The Color Picker window.

Once the color is selected, it is applied to the EditField control.

Screen shot.
Displaying all the system fonts in a contextual menu.

When ContextualMenu 2 is loaded, it will first display all the fonts available on the system using the Font() function. When a particular font is selected, it is then applied to the EditField control (through the Action event):

Screen shot.
Applying the font change to the selected text.

The next control that we need to program is the Slider control. When the user clicks on the Slider control, we want the size of the selected text to be changed, and so we insert the following codes in the ValueChanged event of the Slider control:

Screen shot.
Changing the size of the text via the Slider control.

We are now left with two more controls to code: the Save and Load button. Instead of coding them directly, I want to create two methods so that these two functionalities can be re-used. To do so, go to the Edit menu and select New Method, and type in the name of the method you are creating. You can also specify any input parameters and the output of your method. For my case, I don't need any of these.

Screen shot.
Adding methods to the project.

Insert the codes for the LoadFile method:

Screen shot.
Coding the LoadFile() method

Insert the codes for the SaveFile method:

Screen shot.
Coding the SaveFile() method.

Note that in the LoadFile() method, you used the GetOpenFolderItem function to load a file of type "application/text" from the disk. In order for the application to load the correct file type, you need to add in the file type by clicking on the Edit menu and selecting File Types:

Screen shot.
Adding a new file type to your project.

Now that we have defined our two methods, we can simply link the Load and Save buttons to the two methods by calling the method names:

Screen shot.
Calling the method.

That's it. You can now run the application by pressing Command-R.

Pages: 1, 2, 3

Next Pagearrow