# Creating The Resources

> The next step doesn't involve the PST development tools at all. Unlike Java or other Smalltalk systems where the graphic widgets are implemented in native Win32 code, PST uses a different approach. Since the widgets are part of the Palm OS, we use those, and just bind our code to them. We have to create a resource recipe file which defines our forms and the widgets that live on them. To create this resource file, use any text editor such as VIM or Emacs.

> Actually, a better way is to use a builder tool. There are currently two choices: PilotMag and ThTkBuilder. PilotMag is what I used to create the resource file for this project. It is a payware program, but well worth it. You can graphically layout your forms, menus and whatnot, and have it generate the resource file. It was designed to work with the GCC for Palm C/C++ compiler, so is geared for C/C++ development, but is very useful just for the GUI builder. ThTkBuilder is another version of PST that contains a built-in GUI builder. ThTkBuilder is still an alpha product, but it looks extremely promising. In addition to generating the resource file, ThTkBuilder will write a fair amount of the binding code that I will be demonstrating later on for you.

> Below is the full text of the resource file. You should type this into your editor and save it in your project directory as `ManHourCalculator.rcp`. (Don't type the numbers at the beginning of the lines; those are for reference in the rest of this section.)

>      0  MENU ID 1313
>      1  BEGIN
>      2      PULLDOWN "Main"
>      3      BEGIN
>      4          MENUITEM "About..." ID 1314
>      5          MENUITEM "Exit" ID 1315
>      6      END
>      7  END
>      8
>      9  FORM ID 1304 AT (0 0 160 160)
>     10  NOFRAME
>     11  NOSAVEBEHIND
>     12  USABLE
>     13  MENUID 1313
>     14  BEGIN
>     15      TITLE "ManHour Calculator"
>     16      BUTTON "Calculate" ID 1305 AT (50 138 53 13) USABLE LEFTANCHOR FRAME FONT 0
>     17      LABEL "How many hours?" ID 1306 AT (2 25) USABLE FONT 0
>     18      FIELD ID 1307 AT (89 25 40 12) USABLE LEFTALIGN FONT 0 EDITABLE UNDERLINED SINGLELINE MAXCHARS 10 AUTOSHIFT NUMERIC
>     19      LABEL "Hour sure are you?" ID 1308 AT (2 41) USABLE FONT 0
>     20      POPUPTRIGGER "Positive" ID 1309 AT (89 41 51 12) USABLE LEFTANCHOR FONT 0
>     21      POPUPLIST ID 1309 1310
>     22      LIST "List1" ID 1310 AT (89 41 65 33) NONUSABLE DISABLED VISIBLEITEMS 3 FONT 0
>     23      LABEL "Adjusted Hours" ID 1311 AT (2 57) USABLE FONT 0
>     24      FIELD ID 1312 AT (89 57 40 12) USABLE LEFTALIGN FONT 0 NONEDITABLE UNDERLINED SINGLELINE MAXCHARS 10 AUTOSHIFT
>     25  END
>     26
>     27  FORM ID 1004 AT (2 2 156 156)
>     28  NOFRAME
>     29  MODAL
>     30  NOSAVEBEHIND
>     31  USABLE
>     32  BEGIN
>     33      TITLE "About"
>     34      BUTTON "OK" ID 1005 AT (56 136 37 13) USABLE LEFTANCHOR FRAME FONT 0
>     35      LABEL "pst@pocketsmalltalk.com" ID 1008 AT (11 80) USABLE FONT 0
>     36      LABEL "www.pocketsmalltalk.com" ID 1009 AT (10 107) USABLE FONT 0
>     37      LABEL "Home:" ID 1010 AT (11 97) USABLE FONT 1
>     38      LABEL "Mail:" ID 1011 AT (11 68) USABLE FONT 1
>     39      LABEL "ManHour Calculator" ID 1320 AT (39 23) USABLE FONT 0
>     40  END

> If you're lazy and don't feel like typing it in, you can download it here.

> The purpose of this file is to declare the widgets that will show up on our forms, declare the forms themselves, the menus and whatnot, and to place the widgets. Let's look at the file so you will understand what it does. We won't go over every line, just some of the highlights.

> Line 0
>   This line declares a menubar that will have one or more pulldown menus. The `ID 1313` clause gives the menubar a number, or ID, that we will use later to bind it into our code.
> Lines 2 - 6
>   The `PULLDOWN` and the `MENUITEM` keywords create, of all things, a pulldown menu called "Main", and two menu items called "About...", and "Exit".
> Line 9
>   This line creates a form, the fundamental GUI widget, with an ID of 1304, and places it on the Palm screen, covering the entire thing. (The Palm screen is 160x160 pixels.)
> Lines 10 - 12
>   These are options that control how the form looks and works.
> Line 13
>   This line binds the menu created earlier with this form. This line causes the menu we created to show up when the user clicks on the menu button on the Palm, when this form is displayed.
> Line 15
>   This is the text that will appear at the top of the form on the Palm.
> Line 16
>   This creates a push button with the text of "Calculate" on it, and places it at the coordinates in parentheses. The ID is 1305, which we will later use to bind code to the button.
> Line 17
>   This line, as well as all the lines beginning with `LABEL` create static text labels at the specified coordinates.
> Line 18
>   This create a text field that only accepts numeric input.
> Lines 20 - 22
>   Unlike other languages where you create a drop-down listbox by instantiating one widget, here you have to create a "trigger" and the list itself. The trigger is created on line 20, and the list on line 22. These are tied together by line 21.
> Line 24
>   This line creates a textfield that does not accept user input. We will use it to show the user the result of our calculation.
> Line 27 - 40
>   These lines create another form, that we will use for our About box.

> Once this file is created, you need to compile the resources. This is where PilRC comes in. Open a command line window, change into your project directory, and execute this command

> > `pilrc ManHourCalculator.rcp`

> You should end up with three `.bin` files. These are compiled representations of the widgets you specified in the resource file. Now that we've got our resources compiled, we can go back into PST to start the process of binding them to code.

> << Section 1: Setting Up The Packages | Section 3: Defining The Constants >>
> Introduction

Copyright © 2000 Joey Gibson