Example: Defining the classes ScreenPMCapture and ScreenWinCapture describes how to define a platform-specific class. Example: Implementing methods for ScreenPMCapture and ScreenWinCapture describes how to add methods, one of which is platform-specific, to the class. If you completed these examples, but only created a class that works on one platform, you can easily change the class and its methods so they work on the other platform by filing out the code, changing it, and filing the changed code into your image.
Suppose you created the class ScreenPMCapture and implemented its methods. To now create ScreenWinCapture and change the method saveGraphicImage so it grabs BMPs for Windows tools, complete the steps given below.
Begin by filing out the class ScreenPMCapture:
System genericFormat: true
Next, open a Workspace on the filed-out class. (Select
Open from a File menu; then enter the path and file
name.) The displayed file resembles the following:
The file contains the class definition for ScreenPMCapture and its private instance methods. The first set of text (or chunk) contains the class definition. If ScreenPMCapture were an extended class, instead of a defined class, the class definition would not be in the file. The second chunk is the Smalltalk expression !ScreenPMCapture methods !. If the methods were class methods, the expression would read !ScreenPMCapture class methods !. The expression instructs the system to add the methods to the class ScreenPMCapture. Because you filed out in the generic format, the expression does not indicate that the methods are private. The remaining chunks contain method definitions.
The typical sequence of chunks in filed-out code is class definition, public class methods, public instance methods, and private instance methods (as applicable).
As with the IBM Smalltalk format, an exclamation point (!) separates each chunk. An empty chunk (! !) ends the file.
To create the class ScreenWinCapture and make the methods suitable for Windows, you must change the filed-out code as follows:
To change references to PM in the code to Win:
Alternatively, you can simply select Replace All. This option replaces all occurrences of the searched-for text throughout the file, without first giving you the chance not to replace specific occurrences of the text.
At this point, you might change the expression !ScreenWinCapture methods ! to to !ScreenWinCapture privateMethods ! so it designates the methods as private. But this change is not necessary.
Now, create the class ScreenWinCapture in your image by filing it into the subapplication DevelopCaptureWin. ( Example: Defining application lineups for OS/2 and Windows describes how to create DevelopCaptureWin. If you have already created DevelopCaptureWin and ScreenWinCapture, but want to complete this example, create another subapplication of DevelopScreenCapture to file the code into. Name it, for example, DevelopFileInTest. You can delete the subapplication after you file in the changed code and examine its contents.)
To file in the changed code:
Note that the Application Manager now names the subapplication as its default above the left pane. Except when filing in code from a Workspace, Transcript, or description pane, you do not need to keep track of what application is the default.
One way to file in the code is to select File In from the Applications menu, and then enter the full path name displayed in the title bar of the Workspace.
For this example, try a different approach:
Object subclass: #ScreenWinCapture instanceVariableNames: 'shell state countDown gc captureMode rectangle widgetMan radio countLabel buttons frame text' classVariableNames: '' poolDictionaries: 'CgConstants CwConstants CfsConstants '!
Now file in the methods:
When you file in methods from a Workspace, Transcript, or description pane, you select code that begins with the Smalltalk expression naming the target class and type of method and that ends with an empty chunk (! !). Thus, you can file in one method, though that method must be preceded by the Smalltalk expression and ended with an empty chunk.
After you file in the code, the system creates the class ScreenWinCapture and its methods. You can browse the new class by clicking on ScreenWinCapture now displayed in the Application Manager and then selecting Browse Class from the Classes menu.