Use GormGorm is the tool to build the user interface for GNUstep application. The idea is that there is an instance called "controller", and an user interface called "view". The "view" is created by Gorm, and the "controller" controls the behavior of "view". Therefore, any event from this "view" will go to this "controller", and this "controller" can control the GUI component of this "view". Since the "view" is created by Gorm, and the "controller" is written as source code, there must be some way to connect these two instances. "Controller" must define the variables which correspond to the components on the "view" in order to control them. These variables called "outlets". Once these outlets (variables) are connected to the components on the "view", manipulation on these outlets equals to the manipulation on these components. Any event on the "view" should call a specific method in the "controller". For example, when user click the menu "Quit", it should call the method -terminate: in NSApp so that this application can quit. The methods called by the components on the "view" are called "actions". So the "actions" are the "methods" in the "controller" which are called when the components on the "view" are triggered. And the "outlets" are the variables in "controller" which corresponds to the components on the "view". There is a tutorial which use the older Gorm. The operation might be a little bit different, but the comcept of "action" and "outlet" are the same. They are worthy to read. Gorm can also be used with ProjectCenter.Assume the Gorm is installed. Use 'openapp Gorm" to start. You should see these window/panels of Gorm:Choose "Document->New Application" to create a new user interface for this application. A window and a menu will appear. They are the main window and the main menu for this new application.Click the window, and the inspector will become "NSWindow Inspector". Change the "Title" in "Attributes". Remember to press enter key to make it effective. You can change the size of this windows by drag the border, or set the number in "Size" in inspector.For the text inside the window, drag the "title" from palettes into the main window like this:Double-click it and type.That's all for the main window. Let's work on the menu. Besides the default "Hide" and "Quit", I need an "Info" menu. Click on the left button of the palettes to show up the menus. Drag the "Info" submenu into the main menu. Clicking on the new "Info" menu item will show the submenu "Info".That's all the user interface I need. Since I don't manipulate any GUI component in this example, I don't need any outlet. But some GUI component need to set the "action" so that they can trigger the specific events. Therefore, I need to connect these GUI components to the "actions"."Actions" are the methods in the controller for this view. And where is the controller for the main window ? The answer is the NSApp in this case. Since NSApp already exist, and contains many built-in methods, I don't even need to write any method by my own. I only need to connect each GUI component to the existing method in NSApp. The more general examples about "outlets" and "actions" will be in the following tutorials.There are two steps to connect GUI component to the action in an specific instance. The first step is connect the GUI component to the instance which has the "action". The second is to specify the "action" I want to use in this instance.I start with the "Info Panel...", which is a "NSMenuItem". There is a method -orderFrontStandardInfoPanel in NSApp. Therefore, I need to connect the NSMenuItem "Info Panel" to NSApp. Then where is NSApp ? Since this is the main menu of this application, its owner is this application. Therefore, the instance NSOwner is NSApp. Look at the "Attributes" of NSOwner. It will tell you which class the NSOwner is.Hold on the "Ctrl" key, and drag the "Info Panel..." into the NSOwner. There should be a small green circle with "s" (source) and a red circle with "t" (target). That means the source is connected to the target.Look at the inspector now. It should be the "NSMenuItem Inspector" because the "Info Panel" is a NSMenuItem instance. Choose the "Connections" in the inspector. In the "Outlets" column, there is a "target", which means the target of this NSMenuItem. Since I connect "Info Panel" to NSOwer, which is NSApp, the target refers to NSApp. Click on this target, it will show all the actions available in the target, NSApp. In the "Actions" column, you can find the method -orderFrontStandardInfoPanel:. Choose it, and click the "Connect" button in the inspector.In the "Connections" column, you can see this NSMenuItem is connected to the method -orderFrontStandardInfoPanel: of NSOwer, which is NSApp in this case. Keep doing that for the menu "Hide" and "Quit": Ctrl-drag, and connect the proper action.Then the part for Gorm is done ! Save it as "HelloWorld.gorm", which is actually an directory and contains all the stuff it needs.I still need the basic GNUmakefile and main.m to make it work. Here are the files:GNUmakefile:
include $(GNUSTEP_MAKEFILES)/common.make
APP_NAME = HelloWorld
HelloWorld_HEADERS =
HelloWorld_OBJC_FILES = main.m
HelloWorld_RESOURCE_FILES = HelloWorldInfo.plist HelloWorld.gorm
HelloWorld_MAIN_MODEL_FILE = HelloWorld.gorm
include $(GNUSTEP_MAKEFILES)/application.make
main.m:
#include <AppKit/NSApplication.h>
int main(int argc, const char *argv[])
{
return NSApplicationMain (argc, argv);
}
HelloWorldInfo.plist:
{
ApplicationDescription = "Hello World Tutorial";
ApplicationIcon = "";
ApplicationName = HelloWorld;
ApplicationRelease = 0.1;
Authors = "";
Copyright = "Copyright (C) 200x by ...";
CopyrightDescription = "Released under...";
FullVersionID = 0.1;
URL = "";
}
You can find the extra entry, HelloWorld_MAIN_MODEL_FILE, which means the HelloWorld.gorm is the main user interface file for this application. It is a shortcut to use the main user interface. Therefore, in main.m, I can use very simple codes than previous lesson. In the following tutorials, I will show the more general usage of Gorm file.