TweetFollow Us on Twitter

PP TextEdit
Volume Number:12
Issue Number:3
Column Tag:Getting Started

PowerPlant and TextEdit

By Dave Mark, MacTech Magazine Regular Contributing Author

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Over the next few months, we’re going to implement a TextEdit application using PowerPlant. We’ll start off this month by implementing a classic TextEdit window with a single text style. Next month, we’ll add the code to save and open documents created with this application.

Planning Our Project

Let’s take a look at the steps we’ll need to take to implement a TextEdit window in a PowerPlant application. We’ll need to:

• Create a new project using the PowerPlant stationery.

• Replace the stationery Constructor file with a copy we saved in our project folder.

• Replace the stationery source code files in the project (both the main .cp file and its corresponding .h file) with copies of the files we save in our project folder.

• Use Constructor to create a TextEdit window view in our project resource file.

• Modify the source code to base the default window on the new view. This last change is only one line of code.

Before you read on, take some time to try this yourself. At this point, you should know enough about PowerPlant to implement the project yourself without step-by-step instructions (don’t worry, we’ll get to the step-by-step instructions in a minute, just in case). More than likely, if you need help, it will be with the fourth step, creating a TextEdit view in Constructor. Here’s a hint. First create an LWindow, then add an LScroller to the LWindow, then add an LTextEdit inside the LScroller. Go back and check out the PictScroller project (MacTech 11.12) if you need a refresher.

Before you continue, check to see which version of Constructor you have. You shoul;d be using Constructor 2.0.1 or later. CW7 shipped with Constructor 2.0, which has a bug which directly affects this project. Basically, Constructor 2.0 doesn’t always save ‘ppop’ resources correctly, and you can end up with some funky results. Fortunately, upgrading to Constructor 2.0.1 is painless. Get on the web and check out:

http://www.metrowerks.com/tools/software/updates/current

About halfway down the page, you’ll find and ftp URL for the Constructor 2.0.1 update. Donwload the updater and bring your Constructor back to the future.


Creating the PPEdit Project

OK, here are the step-by-step instructions I promised. We’ll start off by building our project and replacing the stationery files:

• Create a new folder called PPTextEdit.

• Launch CodeWarrior and create a new project named PPTextEdit.µ, using the PowerPlant stationery.

• In the project window, double-click on the file <PP Starter Resource>.rsrc. This will open the file in Constructor.

• In Constructor, do a Save As... and save the file in the PPTextEdit folder as PPTextEdit.rsrc.

As mentioned in last month’s column, this last step tells Constructor to completely duplicate the file, and not just the resources it uses. This is definitely the right way to replace the stationery resource file.

By the way, the new PowerPlant manual (you’ll find it on the CW8 CD) has a cool tip concerning PowerPlant resource files. When you create a new PowerPlant project, divide your resources into two groups. Put all the Constructor-related resources in one resource file (give it the creator code 'MWC2') and put all your other resources in a second resource file (give it the creator code 'RSED' if you use ResEdit or 'Doug' if you use Resorcerer). This way, when you double-click on your Constructor resource file, Constructor will be launched, and when you double-click on your regular resource file, your favorite resource editor will be launched.

• Quit Constructor and return to CodeWarrior.

• Add the file PPTextEdit.rsrc to the project.

• Delete the file <PP Starter Resource>.rsrc from the project.

• In the project window, double-click on the file <PP Starter Source>.cp.

• Select Save As... from the File menu and save the file as PPTextEdit.cp in the PPTextEdit folder.

• Scroll to the top of PPTextEdit.cp and find the line:

#include "<PP Starter Header>.h"

Select everything between the quotes (don’t select the quotes) and type AppleD (Open Selection from the File menu). This opens the stationery file <PP Starter Header>.h.

• Select Save As... from the File menu and save the header file as PPTextEdit.h in the PPTextEdit folder.

• Change the #include to read:

#include "PPTextEdit.h"

• Select Preferences... from the Edit menu and scroll to either the “68K Project” or “PPC Project” pane, depending on which machine you are developing for.

• In the “Application Info” area, change the File name to PPTextEdit and use the 'SIZE' flags popup to make the menu look like the one in Figure 1.

Figure 1. Be sure your SIZE flags are set like this in the CodeWarrior preferences (see the PPC Project or 68K Project pane).

This last step ensures that your application supports high level events. If your app supports high level events, PowerPlant sends an 'oapp' Apple event when the application starts up. This causes the function CPPStarterApp::StartUp() to get called which, in turn, issues a cmd_New command. Simply put, if your application’s 'SIZE' flags don’t indicate that your app is high level event-aware, a new window won’t appear at startup.

Creating the TextEdit View in Constructor

Our next step is to create the new TextEdit view in Constructor.

• In the CodeWarrior project window, double-click on the file PPTextEdit.rsrc to launch Constructor.

• In the main window, click on the default LWindow (ID 1) and press the Delete key to get rid of it. The main window should now be empty.

If you are using the version of Constructor that shipped with CW8 (2.1a1 or later), the main window looks a little different. Instead of a scrolling list of icons, each of which has an associated list of resources, the new Constructor (see Figure 2) features collapsing triangles, as well as a menu editor, so you can edit your menus without leaving Constructor. Very cool!

Figure 2. This month’s Constructor file, as seen in the version of Constructor that shipped on January’s CW8 CD.

• Select New Resource from the Edit menu to create a new LWindow view.

• Give the new view a resource ID of 1000 and a name of TextEdit.

In the old Constructor, you’ll need to click on the view in the main window and select Resource Info from the Edit menu (AppleI) to change the resource ID. In the new Constructor, you can enter the resource ID when you first create the view. Much better.

• In the main window, double-click on the new view to open the TextEdit view’s editing window.

• The view editing window will contain a single window. Double-click on the title bar of that window to bring up the TextEdit view’s pane info window.

• Change the pane info window to match the settings shown in Figure 3.

• Close the pane info window (leaving the view-editing window open).

PowerPlant terminology reminder: All things are panes. Some panes are also views. A view is a pane that can enclose other panes. So a window is a pane that happens to also be a view. A control is a pane and is never a view (you can’t embed a pane inside a control pane).

Figure 3. The resource info for the TextEdit LWindow view.

• Drag an LScroller from the palette onto the window in the view editing window.

• Double-click the LScroller to bring up its pane info window.

• Change the LScroller’s pane info window to match the settings shown in Figure 4.

Be sure to enter -1 in the horizontal scroll bar’s left indent field. This tells PowerPlant to leave out the scroll bar on the bottom of our TextEdit window.

Note that we assigned the LScroller a pane ID of 1001. Also, note that we entered a Scrolling View ID of 1002. This second ID tells Constructor and PowerPlant which pane we want controlled by this LScroller. We’ll create an LTextEdit pane next and give it an ID of 1002.

• Close the LScroller’s pane info window (leaving the view-editing window open).

Figure 4. The pane info for the LScroller. Note that the horizontal scroll bar was disabled.

• Drag an LTextEdit from the palette onto the LScroller in the view editing window.

• Double-click the LTextEdit to bring up its pane info window.

• Change the LTextEdit’s pane info window to match the settings shown in Figure 5.

Figure 5. The pane info for the LTextEdit pane. Note that the TextTraits ID is set to 1002. We’ll create a new Text Trait resource just for this LTextEdit.

Note that the LTextEdit has a pane ID of 1002. That’s to connect it to the LScroller. Note also that the Text Traits ID is set to 1002. In a moment, we’ll create a text trait resource (with an ID of 1002) that specifies the format of the text drawn in this LTextEdit pane.

• Close the LTextEdit’s pane info window (leaving the view editing window open).

• Close the view editing window for our LWindow, leaving the main window open.

• Select Show Hierarchy from the Display menu.

• When the hierarchy appears, be sure that it matches the hierarchy shown in Figure 6, with the LScroller embedded in the LWindow and the LTextEdit embedded in the LScroller.

Figure 6. The pane/view hierarchy, showing the LScroller embedded in the LWindow and the LTextEdit embedded in the LScroller.

• Close the hierarchy window.

• In the main window, click on the Text Traits icon (as opposed to the Views icon).

• Create a new text trait resource by selecting New Resource from the Edit menu.

• Change the text trait settings to match those shown in Figure 7.

Figure 7. The specifications for our text traits resource.

• Close the Text Traits window.

• In the main window, click on the new Text Trait you just created, then select Resource Info from the Edit menu.

• Change the resource ID of the new text traits resource to 1002.

• Close the resource info window.

If you are using the new Constructor, your method for creating a new text trait resource will be slightly different. In the main window, click on the main Text Traits heading, then select New Text Traits Resource from the Edit menu. When the new resource appears in the list, double-click on it to open the trait editing window, or click on it and select Resource Info from the Edit menu to edit the resource info.

• Save your changes, then quit Constructor.

One Slight Source Code Change

One slight source code change, then we’re done. All we have to do is change the constant that tells the application which view to open on startup. The PowerPlant stationery sets things up so the 'ppob' resource with an ID of 1 is used as the basis for the application’s default window. All we need to do is change the 1 to 1000, so our LWindow 1000 will get used instead.

• Back in CodeWarrior, open up the source code file PPTextEdit.cp.

• Towards the top of the file, you’ll find the line:

const ResIDTwindow_Sample = 1;// EXAMPLE

• Change the 1 to a 1000, so the line reads:

const ResIDTwindow_Sample = 1000;  // EXAMPLE

Running the Application

That’s it! Your application is now ready to rock and roll.

• Select Run from the Project menu.

After your source code is compiled and the project is linked, your new TextEdit application will run and a new TextEdit window will appear. Click in the window, then type in a bunch of text. Notice that the text appears in red, 9-point Geneva. As is, PowerPlant does not yet support styled TextEdit, though there are some third-party classes available that do. I’m guessing that we’ll see styled TextEdit built in to PowerPlant before too long.

Try creating multiple windows (select New from the File menu) and copy and paste between the windows. This is cool. You get a lot for free with PowerPlant.

Till Next Month...

One thing you’ll notice is that our application has no way of saving the text to disk or loading the contents of a file into a window. Guess what we’ll be doing next month. Till then, get hold of the PowerPlant manual (a great job of writing by Jim Trudeau, by the way), and start reading about the LDocument class.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Dropbox 193.4.5594 - Cloud backup and sy...
Dropbox is a file hosting service that provides cloud storage, file synchronization, personal cloud, and client software. It is a modern workspace that allows you to get to all of your files, manage... Read more
Google Chrome 122.0.6261.57 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
Skype 8.113.0.210 - Voice-over-internet...
Skype is a telecommunications app that provides HD video calls, instant messaging, calling to any phone number or landline, and Skype for Business for productive cooperation on the projects. This... Read more
Tor Browser 13.0.10 - Anonymize Web brow...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Deeper 3.0.4 - Enable hidden features in...
Deeper is a personalization utility for macOS which allows you to enable and disable the hidden functions of the Finder, Dock, QuickTime, Safari, iTunes, login window, Spotlight, and many of Apple's... Read more
OnyX 4.5.5 - Maintenance and optimizatio...
OnyX is a multifunction utility that you can use to verify the startup disk and the structure of its system files, to run miscellaneous maintenance and cleaning tasks, to configure parameters in the... Read more

Latest Forum Discussions

See All

Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »
Live, Playdate, Live! – The TouchArcade...
In this week’s episode of The TouchArcade Show we kick things off by talking about all the games I splurged on during the recent Playdate Catalog one-year anniversary sale, including the new Lucas Pope jam Mars After Midnight. We haven’t played any... | Read more »
TouchArcade Game of the Week: ‘Vroomies’
So here’s a thing: Vroomies from developer Alex Taber aka Unordered Games is the Game of the Week! Except… Vroomies came out an entire month ago. It wasn’t on my radar until this week, which is why I included it in our weekly new games round-up, but... | Read more »
SwitchArcade Round-Up: ‘MLB The Show 24’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for March 15th, 2024. We’re closing out the week with a bunch of new games, with Sony’s baseball franchise MLB The Show up to bat yet again. There are several other interesting games to... | Read more »
Steam Deck Weekly: WWE 2K24 and Summerho...
Welcome to this week’s edition of the Steam Deck Weekly. The busy season has begun with games we’ve been looking forward to playing including Dragon’s Dogma 2, Horizon Forbidden West Complete Edition, and also console exclusives like Rise of the... | Read more »
Steam Spring Sale 2024 – The 10 Best Ste...
The Steam Spring Sale 2024 began last night, and while it isn’t as big of a deal as say the Steam Winter Sale, you may as well take advantage of it to save money on some games you were planning to buy. I obviously recommend checking out your own... | Read more »
New ‘SaGa Emerald Beyond’ Gameplay Showc...
Last month, Square Enix posted a Let’s Play video featuring SaGa Localization Director Neil Broadley who showcased the worlds, companions, and more from the upcoming and highly-anticipated RPG SaGa Emerald Beyond. | Read more »
Choose Your Side in the Latest ‘Marvel S...
Last month, Marvel Snap (Free) held its very first “imbalance" event in honor of Valentine’s Day. For a limited time, certain well-known couples were given special boosts when conditions were right. It must have gone over well, because we’ve got a... | Read more »
Warframe welcomes the arrival of a new s...
As a Warframe player one of the best things about it launching on iOS, despite it being arguably the best way to play the game if you have a controller, is that I can now be paid to talk about it. To whit, we are gearing up to receive the first... | Read more »
Apple Arcade Weekly Round-Up: Updates an...
Following the new releases earlier in the month and April 2024’s games being revealed by Apple, this week has seen some notable game updates and events go live for Apple Arcade. What The Golf? has an April Fool’s Day celebration event going live “... | Read more »

Price Scanner via MacPrices.net

Apple Education is offering $100 discounts on...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take $100 off the price of a new M3 MacBook Air.... Read more
Apple Watch Ultra 2 with Blood Oxygen feature...
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose... Read more
New promo at Sams Club: Apple HomePods for $2...
Sams Club has Apple HomePods on sale for $259 through March 31, 2024. Their price is $40 off Apple’s MSRP, and both Space Gray and White colors are available. Sale price is for online orders only, in... Read more
Get Apple’s 2nd generation Apple Pencil for $...
Apple’s Pencil (2nd generation) works with the 12″ iPad Pro (3rd, 4th, 5th, and 6th generation), 11″ iPad Pro (1st, 2nd, 3rd, and 4th generation), iPad Air (4th and 5th generation), and iPad mini (... Read more
10th generation Apple iPads on sale for $100...
Best Buy has Apple’s 10th-generation WiFi iPads back on sale for $100 off MSRP on their online store, starting at only $349. With the discount, Best Buy’s prices are the lowest currently available... Read more
iPad Airs on sale again starting at $449 on B...
Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices again for $150 off Apple’s MSRP, starting at $449. Sale prices for online orders only, in-store price may vary. Order online, and choose... Read more
Best Buy is blowing out clearance 13-inch M1...
Best Buy is blowing out clearance Apple 13″ M1 MacBook Airs this weekend for only $649.99, or $350 off Apple’s original MSRP. Sale prices for online orders only, in-store prices may vary. Order... Read more
Low price alert! You can now get a 13-inch M1...
Walmart has, for the first time, begun offering new Apple MacBooks for sale on their online store, albeit clearance previous-generation models. They now have the 13″ M1 MacBook Air (8GB RAM, 256GB... Read more
Best Apple MacBook deal this weekend: Get the...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New 15-inch M3 MacBook Air (Midnight) on sale...
Amazon has the new 15″ M3 MacBook Air (8GB RAM/256GB SSD/Midnight) in stock and on sale today for $1249.99 including free shipping. Their price is $50 off MSRP, and it’s the lowest price currently... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
Relationship Banker *Apple* Valley Main - W...
…Alcohol Policy to learn more. **Company:** WELLS FARGO BANK **Req Number:** R-350696 **Updated:** Mon Mar 11 00:00:00 UTC 2024 **Location:** APPLE VALLEY,California Read more
Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill WellSpan Medical Group, York, PA | Nursing | Nursing Support | FTE: 1 | Regular | Tracking Code: 200555 Apply Now Read more
Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.