Guide To The Gorm Application: Richard Frith-Macdonald
Guide To The Gorm Application: Richard Frith-Macdonald
Version 0.9.2 (for use with gnustep-gui version 0.9.4) (and with gnustep-base version 1.10.0)
Copyright c 1999,2000 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modied versions of this manual under the conditions for verbatim copying, provided also that the section entitled GNU Library General Public License is included exactly as in the original, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modied versions, except that the section entitled GNU Library General Public License may be included in a translation approved by the author instead of in the original English. Note: The Gorm application is in alpha release. You will be performing a valuable service if you report any bugs you encounter.
Table of Contents
Copying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Contributors to Gorm . . . . . . . . . . . . . . . . . . . . . . . . . 2 1 Installing Gorm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.0.1 1.0.2 1.0.3 Required software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Build and Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Trouble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
News . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17 Noteworthy changes in version 0.9.2 . . . . . . . . . . . . . . . . . . . . 4 Noteworthy changes in version 0.9.0 . . . . . . . . . . . . . . . . . . . . 4 Noteworthy changes in version 0.8.0 . . . . . . . . . . . . . . . . . . . . 4 Noteworthy changes in version 0.7.7 . . . . . . . . . . . . . . . . . . . . 5 Noteworthy changes in version 0.7.6 . . . . . . . . . . . . . . . . . . . . 5 Noteworthy changes in version 0.7.5 . . . . . . . . . . . . . . . . . . . . 6 Noteworthy changes in version 0.6.0 . . . . . . . . . . . . . . . . . . . . 6 Noteworthy changes in version 0.5.0 . . . . . . . . . . . . . . . . . . . . 6 Noteworthy changes in version 0.4.0 . . . . . . . . . . . . . . . . . . . . 6 Noteworthy changes in version 0.3.1 . . . . . . . . . . . . . . . . . . . 7 Noteworthy changes in version 0.3.0 . . . . . . . . . . . . . . . . . . . 7 Noteworthy changes in version 0.2.5. . . . . . . . . . . . . . . . . . . 7 Noteworthy changes in version 0.2.0 snapshot.. . . . . . . . . . 7 Noteworthy changes in version 0.1.0 . . . . . . . . . . . . . . . . . . . 8 Noteworthy changes in version 0.0.3 . . . . . . . . . . . . . . . . . . . 8 Noteworthy changes in version 0.0.2 . . . . . . . . . . . . . . . . . . . 8 Noteworthy changes in version 0.0.1 . . . . . . . . . . . . . . . . . . . 8 2.17.1 To Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1 3.2 What You Must Know To Understand This Manual. . . . . . . 11 3.1.1 Major features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 About this Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 5
Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.1 5.2 Notes on implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
ii
6 7
7.4 7.5
Creating an Application . . . . . . . . . . . . . . . . . . . 19
8.1 8.2 Creating A Class In Gorm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using The Outline View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.1 Adding Outlets In The Outline View . . . . . . . . . . . . 8.2.2 Adding Actions In the Outline View . . . . . . . . . . . . Using The Class Edit Inspector. . . . . . . . . . . . . . . . . . . . . . . . . . 8.3.1 Adding Outlets In The Inspector. . . . . . . . . . . . . . . . 8.3.2 Adding Actions In the Inspector . . . . . . . . . . . . . . . . Instantiating The Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding Controls from the Palette . . . . . . . . . . . . . . . . . . . . . . . 8.5.1 Making Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving the gorm le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Generating .h and .m les from the class. . . . . . . . . . . . . . . . . 19 19 19 19 20 20 20 20 20 20 21 21
8.3
10
Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . 26
10.1 Gorm le format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.1 The Name Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.2 The Custom Class Table . . . . . . . . . . . . . . . . . . . . . . 10.1.3 Connections Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . Custom Class Encoding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.1 Restrictions On Your Custom Subclasses . . . . . . . Palettes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.3.1 Graphical Objects In A Palette . . . . . . . . . . . . . . . . 10.3.2 Non Graphical Objects In A Palette . . . . . . . . . . . 26 26 26 26 26 27 27 27 28
10.2 10.3
iii
11
Concept Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Copying
Copying
See the le COPYING.
Contributors to Gorm
Contributors to Gorm
Gregory John Casamento <greg [email protected]> Is the current maintaner of Gorm. Has implemented lots of new features and rewritten large portions of the existing code. Richard Frith-Macdonald <[email protected]> wrote the original version of Gorm as part of the GNUstep project. Pierre-Yves Rivaille <[email protected]> Is also a major contributor to the Gorm application.
1 Installing Gorm
1.0.1 Required software
You need to have the GNUstep core libraries installed in order to compile and use Gorm. The core packages are, at a minimum: gnustep-make gnustep-base gnustep-gui gnustep-back See http://www.gnustep.org/ for further information.
1.0.3 Trouble
Give us feedback! Tell us what you like; tell us what you think could be better. Send bug reports and patches to [email protected].
Chapter 2: News
2 News
2.1 Noteworthy changes in version 0.9.2
NOTE: This is mainly a bugx release. Some improvements to the procedure for removing connections. Corrected various issues with header parsing. Now closes windows which were opened during interface testing such as font panels, info panels, etc. Minor corrections to background color for a number of inspectors. Improvements to gmodel importation. Better detection of when the user is utilizing a user bundle. Gorm will now warn the user with a panel. Various improvements in documentation
Chapter 2: News
Chapter 2: News
Chapter 2: News
Chapter 2: News
Chapter 2: News
Chapter 2: News
10
Class info (outlets and actions) is specied in ClassInformation.plist and needs to be present so that the app knows what outlets/actions an object has (and therefore what connections can be made). The view size inspector is working - allowing you to set the size of the subviews within a window. The attributes inspector for FilesOwner is working, so you can dene the class of the les owner (it defaults to NSApplication). There is a crude panel for setting the name of the selected object. Ive created a couple of new images and got rid of the two NeXT images that were lurking in there. There is a Testing directory, with a GormTest application that lets you load a nib for testing - it assumes that the nib will set its FilesOwners delegate to point to a window, and makes that window the key window ... 23 December 1999 Last work before christmas ... Various bits of tidying up plus Added an evil hack of a generic attributes inspector ... This looks through all the methods of the selected object to nd those taking a single argument and beginning with set. It makes all these setting methods (whose argument is a simple scalar type or an object) available for you to invoke from the inspector panel. This makes it possible to set pretty much any attribute of any object, but you do need to have the GNUstep header les to hand, so you can tell what numeric values to enter to achieve a desired result.
2.17.1 To Do
Debug and stabilize existing code.
Chapter 3: Overview
11
3 Overview
Gorm is an application for creating the user interface (and possibly entire applications) for a GNUstep application. Initially a close clone of the old NeXTstep 3.3 Interface Builder application, I expect that Gorm will mutate beyond the capabilities of that app. GNUstep is an object-oriented programming framework and a collection of tools developed for or using the GNUstep libraries. You can nd out more about GNUstep at http://www.gnustep.org The basic idea behind Gorm is simple - it provides a graphical user interface with which to connect together objects from the GNUstep libraries (as well as custom-written objects) and set their attributes in an easy to use manner. The collection of objects is then saved as a document which can either be re-loaded into Gorm for further editing, or can be loaded into a running GNUstep application in order to provide that application with a user interface or some subsystem.
Chapter 4: Usage
12
4 Usage
Here is a description of the menu structure and what each menu does Info The Info menu item produces a submenu ... Info Panel A panel giving very limited information about Gorm Preferences (not implemented) A panel allowing you to set preferences about how Gorm operates Help (not implemented) A panel providing general help on using Gorm Document The Document menu item produces a submenu ... Open This produces an open panel that lets you open a Gorm document. You use this if you want to use Gorm to edit an exisiting document. New Application This creates a new application document within Gorm, you may then use the Palettes panel to drag new objects into the document. New Module Contains a submenu, which also contains: New Empty produces an empty document with only NSFirst and NSOwner. New Inspector produces a document with NSOwner, NSFirst and a window which is the correct size for an Inspector. New Palette produces a document which is like the one by New Inspector, but its window is the right size for a Palette. Save This saves the current document Save As This saves the current document to a new le and changes the document name to match the new name on disk. Save All This saves all documents currently being edited by Gorm. Revert To Saved This removes all changes made to the document sunce the last save, or since the document was opened. Test Interface This provides interactive testing of the active document. To end testing, you need to select the quit menu item. Miniaturize This miniaturises the active document (or whatever panel is currently key).
Chapter 4: Usage
13
Close This closes the currenly active document. Debug Prints some useful internal information. Load Sound Loads a sound into the .gorm le. Image Loads an image into the .gorm le. Edit In addition to the usual Cut, Copy, Paste, Delete Select All, this menu also contains: Group Which produces a submenu In Splitview Groups views into an NSSplitView. Gorm does this based on the relative positions of the views being grouped. It determines the orientation and the order of th views and then groups them either vertically or horizontally in the order they appear on the screen. In Box Simply groups all of the views into one NSBox. In ScrollView Simply groups all of the views into one NSScrollView. Ungroup Ungroups the contained views. Set Name This allows the user to set a name for a given object in the Objects view in the main document window. Disable Guideline This item toggles between Enable Guideline and Disable Guideline. This allows the user to turn on or o the guides which appear when placing views in a window or view in Gorm. Classes Contains menus for working with classes. Create Subclass Creates a subclass of the currently selected class in the current document classes view. Load Class Loads a class from a .h le into the current document. Create Class Files Generates a .h and .m le from the currently selected class in the current document classes view. Instantiate Creates an instance of the selected class in the current document classes view. Add Outlet/Action Adds an outlet or an action depending on what is selected in the document classes
Chapter 4: Usage
14
view. If the outlet icon is selected, it will add an outlet, if it the action icon is selected it will add an action. Remove Removes the currently selected outlet, action or class. Tools Contains the inspector and the palette menus Inspector Shows the inspector Palette Shows the palette Load Palette Opens a le panel and allows the user to load a palette into Gorm. Windows Shows currently open windows. Services Shows currently available services. Hide Hides the application. Quit Quits the application.
Chapter 5: Implementation
15
5 Implementation
5.1 Notes on implementation
The IB documentation on how object selection is managed and how editors and inspectors are used is unclear ... so Ive gone my own way. 1. When a document is loaded, the document object creates an editor attached to each top-level object in the user interface (NSMenu and NSWindow objects). These editors must be aware of their edited objects being clicked upon, and clicking on one of these should cause the corresponding editor to become the active editor. The active editor is responsible for handling selection of the edited object (and any objects below it in the object hierarchy). Upon change of selection, the editor is responsible for sending an IBSelectionChangedNotication with the selection owner (normally the editor itsself) as the notication owner. The main application watches for these notications in order to keep track of who has the selection.
5.2 Connections
The connection API is the same as that for IB, but with the extension that the document object must implement [-windowAndRect:forObject:] to return the window in which the object is being displayed, and the rectangle enclosing the object (in window base coordinates). This information is needed by Gorm so that it can mark the connection. The editors mananging the drag-and-drop operation for a connection must call [NSApp -displayConnectionBetween:and:] to tell Gorm to update its display. This method sets the values currently returned by [NSApp -connectSource] and [NSApp -connectDestination].
Chapter 6: Preferences
16
6 Preferences
The preferences panel contains a number of useful customizable options which can be used to modify the behavior of Gorm. Some of these defaults can be safely modied from the command line by the user. PreloadHeaders The user can dene a set of headers to load when Gorm starts creation of a new .gorm le. This is useful when the user is building a framework or a set of interfaces for a large application. ShowInspectors Controls whether the inspector shows when Gorm is started. ShowPalettes Controls whether the palettes window shows when Gorm is started. BackupFile Determines if the old .gorm is moved to .gorm~ when the modied version is saved. AllowUserBundles If the user sets this to YES, they will still get a warning, but Gorm wont quit.
17
7 Basic Concepts
This chapter will explain some of the basic things you need to understand before starting work on a new application.
7.3.1 Responders
A responder is any subclass of NSResponder. This includes NSWindow, NSView and all of the NSControl subclasses.
18
The rstResponder of the keyWindow, if one exists. Iterates through all responders by pulling each in the linked list of responders for the key window. It then tries the keyWindow. Then the keyWindows delegate if the application is document based it tries the document controller object for the key window. then it tries the mainWindows list of responders (as above) the mainWindows delegate if the app is document based, it tries the document controller for the main window and nally, it tries the NSApplication delegate. If all of the options in this list are exhausted, it then gives up and returns nil for the object which is to respond.
19
8 Creating an Application
If you have ProjectCenter, you need to open it and create an Application project. Create it with the name FirstApp. From there you can open the MainMenu.gorm by clicking on interfaces and selecting MainMenu.gorm. If Gorm.app is properly installed, you Gorm should start up. If you dont have ProjectCenter, you can create the Gorm le by hand. First you need to start Gorm. You can either do this by doing gopen Gorm.app from a command line prompt, or you can invoke it from the Dock or from the workspaces le viewer. You then need to select the Document menu, and then New Application. This should produce a new document window, with a menu and an empty window. This should be the same as with the ProjectCenter gorm le since this is the basic starting point for an application. For the sections below... only do one or the other, not both.
20
21
22
When you look at the .m for this class, you should see the buttonPressed: method with the commecnt /* insert your code here */ in it. Delete this comment and add [value setStringValue: @Hello];. The class should look like this after youre done: /* All Rights reserved */ #include <AppKit/AppKit.h> #include "MyController.h" @implementation MyController - (void) buttonPressed: (id)sender { [value setStringValue: @Hello]; } @end You recall, we connected the texteld to the value variable. The call above causes the method setStringValue to be invoked on the texteld you added to the window. Also, note that the name of the method is buttonPressed:. This is the action which is bound to the button. When it is pressed the text in the texteld should change to Hello. You now need to build the application either by copying in a GNUmakele and making the appropriate changes or by using ProjectCenters build capability, depending on if you use it or not. This app is available as SimpleApp in the Examples directory under the Documentation directory distributed with Gorm. Hopefully this has helped to demonstrate, albeit on a small scale, the capabilities of Gorm. In later chapters we will cover more advanced application architectures and topics.
23
24
for WinController and select it. You now must connect the window outlet to the Window you added previously. Switch back to the objects view, then Control-Drag not to the window on the screen, but to the windows representation in the objects view. In the connection inspector select the window outlet and click Ok. Save the .gorm as using the name Controller.gorm in the project directory. Generate the Controller.h and Controller.h les as described in the previous section.
25
26
10 Advanced Topics
This section will cover some topics which wont be of general interest to most users. The details in this section pertain to the internal workings of Gorm.
27
A Template - Probably the most interesting of the three. This is a standin class which uses an existing instance created in Gorm to build a custom subclass from. For instance when a window subclass is created, call it MyWindow, a template class called GSWindowTemplate is used to hold the NSWindow created in Gorm as well as the name of the subclass to be created when the class is unarchived outside of Gorm as well as some additional information. When the classes are unarchived in the running app, the designated initializer for that class will be invoked, except in the case of NSControl subclasses. See the Apple documentation for more information. All custom instances have awakeFromNib invoked on them when they are unarchived from the .gorm le. This allows the user to do whatever additional setup that needs to be done, such as setting attribute. Classes which are known are, of course, directly encoded into the .gorm le.
10.3 Palettes
10.3.1 Graphical Objects In A Palette
You are, by now, familiar with the built in palettes which are provided with Gorm. Palettes are a powerful feature which allows the developer to add his/her own objects to Gorm. It is possible for a developer to write custom inspectors, editors and palettes for use with Gorm. A good example of a custom palette is palettetest in the dev-apps/test in the GNUstep distribution. Assuming you dont have that, however, I will explain precisely what you need to do in order to create a simple palette. The entire process is very short and suprisingly simple. First open Gorm and selection Gorm->Document->New Module->New Palette. This will create a palette sized window. Once thats done go to the classes view in the main document window and nd IBPalette in the class list. Create a subclass of
28
that, the name can be whatever you want. For the purposes of our example well call it MyPalette. Drag a custom view to the window and choose the class you would like to add to the palette from one of your custom classes. Once youve done this, generate the code for the classes (discussed in previous chapters). In the code, youll add a method called -(void) nishInstantiate leave it empty for now. In the makele for the palette make sure that the library or framework the view comes from is linked with the palette. Now build the palette. After the palette is built youre ready to load it into Gorm. Go to the preferences panel and go to Palettes. This should bring up a table view. Click on add. You should see a open dialog open. Select the palette bundle with this. If the palette is successfully loaded, you should see the name appear in the list. One thing to note here. Once a palette is loaded, it cant be unloaded until you close and restart Gorm. This is because by loading the palette bundle, the code in the bundle is being linked into Gorm. This cant be undone, once its done. Now, you should see the palette in the set of palettes in the palette window. Simply scroll over to it and select its icon. When you do this, you should see the view that you set up using the custom view displayed as an actual instance. Note that we used one of the techniques listed above, it is possible to use any of the three for any object you add to your palette. You can now drag the view from the palette to a new window.
29
11.0.2 Why does my application crash when I add additional attributes for encoding in encodeWithCoder: or initWithCoder: in my custom class?
If youve selected the custom class by clicking on an existing object and then selecting a subclass in the Custom Class Inspector in Gorms inspector panel, then when the .gorm le is saved, Gorm must use what is called a template to take the place of the class so that when the .gorm is unarchived in the running application, the template can become the custom subclass you specied. Gorm has no way of knowing about the additional attributes of your subclass, so when its archived the template depends on the encodeWithCoder: of the existing class. Also, when AppKit loads the .gorm le, the initWithCoder: on the subclass is called to allow the user to do any actions, except for additional encoding, which need to be done at that time. This is particularly true when non-keyed coding is used, since, with keyed coding, its possible to skip keys that are not present. The application may not crash if keyed coding is used, but Gorm would still not know about the additional attributes and would not be able to persist them anyway. Please see information in previous chapters regarding palettes, if you would like to be able to add your classes to Gorm so that they dont need to be replaced by templates, or proxy objects.
11.0.3 Why does Gorm give me a warning when I have bundles specied in GSAppKitUserBundles?
Some bundles may use poseAs: to aect change in the existing behavior of some GNUstep classes. The poseAs: method causes an issue which may cause Gorm to incorrectly encode the class name for the object which was replaced. This makes the resulting .gorm le unusable when another user who is not using the same bundle attempts to load it.
Concept Index
30
Concept Index
C
Class Edit Inspector . . . . . . . . . . . . . . . . . . . . . . . . . Classes Outline View . . . . . . . . . . . . . . . . . . . . . . . . . Connecting to a Window . . . . . . . . . . . . . . . . . . . . . Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Custom Class Encoding . . . . . . . . . . . . . . . . . . . . . . 20 19 24 21 19 26 Instantiating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
N
Name Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NSFirst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NSFont . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NSOwner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NSResponder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 17 17 17 17
D
defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
P
Palettes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
E
Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
F
FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
R
Responder Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
I
Inspectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
S
Saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Setting the NSOwner . . . . . . . . . . . . . . . . . . . . . . . . 23