TweetFollow Us on Twitter

OD Contain Yourself
Volume Number:12
Issue Number:1
Column Tag:New Apple Technology

OpenDoc: Contain Yourself ...

Updating applications to work with OpenDoc

By Eric Soldan, Apple Developer Technical Support

It’s time to be an OpenDoc™ container application. It’s not too soon, and it’s not too late. So how do you decide if your application should be an OpenDoc container application or not? Here’s an easy test:

• Will your application benefit from Internet access?

If the answer is yes, then being an OpenDoc container application is probably the right thing to do. By becoming an OpenDoc container application, you automatically get the benefits of everything that is OpenDoc, including CyberDog, which will provide component oriented Internet clients and other Internet services. Now is not the time to ignore the Internet bandwagon. It’s worth jumping on. The only question remaining is how to jump. Do you learn Open Transport and MacTCP and recode your entire application to support the Internet? Or do you look for alternatives, like OpenDoc?

A logical question therefore would be: “Is OpenDoc really the fastest way to add Internet to your application?” Adding Internet support with OpenDoc boils down to adding basic OpenDoc support; in this article we will evaluate the difficulty of adding OpenDoc to an existing application. Then you can decide.

The Container Application Library: Your Friend.

CALib, the Container Application Library, has been evolving for a while. It’s looking really good right now. Joshua Susser, of OpenDoc engineering, and I have been adding CALib support to an application I originally developed in Developer Tech Support called DTS.Draw. I wrote DTS.Draw years ago, without ever considering the possibility of adding something like OpenDoc later. DTS.Draw’s document model, while flexible, is a closed model, so adding OpenDoc support is therefore a very interesting test case for CALib.

It turns out that the amount of additional coding necessary is minimal. However, due to CALib’s flexibility, there were many development issues that had to be discussed for quite a while. If these discussions were not held, the implementation would not have been as robust. I will present what we’ve learned from these discussions.

First, let’s talk about DTS.Draw for a while. When adding OpenDoc, it’s important to understand how the existing application works. Since you are probably not familiar with DTS.Draw, I’ll give you a quick overview.

DTS.Draw is an AppsToGo framework based application. AppsToGo is an object-oriented C framework written by DTS. DTS.Draw is also all C code. DTS.Draw is a “standard” drawing application. It has a tool palette of a variety of drawing objects. It has a hierarchical document architecture which allows for grouping and ungrouping of draw objects. It supports infinite undo. It supports drag and drop.

When a document is saved, the object hierarchy is flattened and streamed to the file. When a drag-out occurs, the selected objects are streamed into a handle; this stream represents a sub-hierarchy of the document. This sub-hierarchy is then just a flavor for the clippings file. When a file is opened (or a drag-in occurs), the hierarchy is reconstructed. Very standard stuff.

Here’s a diagram of a representative DTS.Draw document:

For a save, the objects in the hierarchy are streamed in simple tree-walk order, as indicated by the numbering. The drag objects 2, 4, 5, and 6 can be any supported object. The current implementation of DTS.Draw allows for line, rect, round rect, oval, and pie objects. More can be added of course, and this exactly is how we added OpenDoc support to DTS.Draw; we just added a new OpenDoc Part object into the application. The difference with this object is that the content isn’t anything specifically manipulated by DTS.Draw. It is simply a part the user adds to the document. The DTS.Draw object just serves as a “container” for the OpenDoc part. If a user were to add two OpenDoc parts to the above DTS.Draw document, the document hierarchy might end up looking something like:

The implementation in DTS.Draw is relatively simple. The Part object inherits from DTS.Draw’s native rect object. The difference is that it has a much more complex content that the rect object in the standard DTS.Draw application. The content of the Part object can be any OpenDoc part, of course. The content of the Part object is managed using CALib. Given this information, look at this diagram and see exactly what the relationship between the Part objects and CALib :

As shown above, there’s a lot more to the DTS.Draw document now. Fortunately, most of the new stuff is managed by CALib and OpenDoc. CALib uses a “proxy part” to contain the parts that are placed into the document content. Normally, OpenDoc expects there to be a root part that is an OpenDoc container, but since other parts are “embedded” into your application’s non-OpenDoc document, a proxy container part is created and the “embedded” parts are stored in there. The proxy part, as far as OpenDoc is concerned, is what actually contains the other parts that are referenced from the DTS.Draw native content.

The difficulty here is that the proxy part isn’t “real.” It has no geometry information, and OpenDoc doesn’t automatically bind the proxy part to any code, as is the normal case with OpenDoc parts. Thus, OpenDoc is unable to offer the full range of services for the embedded parts. But this is okay. The proxy part isn’t all that smart, nor should it be. It is simply a part that is used by CALib to have somewhere to put the other parts.

So it’s up to DTS.Draw to control the layout and presentation for the OpenDoc parts. Only the application knows the geometry information for the embedded parts, which is stored in DTS.Draw Part objects. The DTS.Draw Part object also has a persistent reference to the corresponding object embedded in the proxy part. Fortunately, CALib offers API calls to help manage these and other OpenDoc interactions, so the above and other OpenDoc related tasks are relatively simple to implement.

For example, to perform screen updates and such, DTS.Draw simply tells CALib to tell the part to draw itself. All that is needed is the Part Ref value, which indicates to CALib which embedded part to draw. The application doesn’t have to care what it references. It references something, and that thing knows how to draw itself.

Streaming Your Objects

Given that the proxy part can’t really deal with containing parts by itself, (i.e., without your application doing the geometry), the proxy part and its embedded parts do not constitute a valid OpenDoc document. This is important when we decide what type of document you want to create when you save it to disk.

The choices are:

1. A Bento stream placed inside your document.

2. Your document stream placed inside a Bento document.

The right choice will of course depend on your application. For DTS.Draw, we chose 1. Choice 1 is closer to existing Macintosh applications. Choice 2 is closer to regular OpenDoc parts. If you were to consider the development choices, from application to OpenDoc part, with CALib applications somewhere in between, your choices look something like this:

Application:

Standard document architecture.

CALib-friendly application:

Standard document architecture with embedded Bento stream.

CALib-savvy application:

Bento document with application data streamed into an OpenDoc storage unit
value.

OpenDoc part editor:

Bento document with part editor data residing in an OpenDoc storage unit.

When considering drag and drop, the above categories are very important. When applications drag something to the desktop, a clippings file is created. When OpenDoc parts are dragged to the desktop, an OpenDoc document is created, instead of a clippings file. This is an important distinction between applications and OpenDoc. Applications create clippings files because they are a standard and flexible intermediate format. OpenDoc parts create OpenDoc documents on a drag-out because an OpenDoc document is already a universal format. There’s no reason to resort to creating a clippings file.

If you are a CALib application, the choice is no longer so clear. Our suggestion is to base your drag-out decision on whether your document format is still “native,” or if you use a Bento file with your native content embedded.

So, if you are a CALib application, what is one to do on a drag-out? The answer lies in the document type. If the document type is an OpenDoc document (CALib-savvy), then the drag-out type is OpenDoc document. If the document type is a standard document (CALib-friendly), then the drag-out type is a clippings file.

DTS.Draw’s native content is simply streamed out. After adding CALib support, this is still the case. The Bento document is streamed out, as well. Here’s the new document format:

Byte offset Description

0 to 3: length of Bento stream

4 to nativeContent - 1: Bento stream

nativeContent to EOF: native content stream, i.e.,
DTS.Draw old format

There was much discussion as to whether or not the Bento stream should be at the front of the file or the end. It turns out that you can do some interesting things if it is at the front of the file. Try out this situation:

1. Your machine has CALib. You add some OpenDoc parts to your DTS.Draw document.

2. You then send the document to some poor individual who doesn’t have CALib or OpenDoc.

Guess what? If the Bento stream is in the front of the file, the unfortunate individual can still use the file with your CALib-friendly application. The user without CALib can actually edit the native content and save it out. The native content changes size, but hey, it’s on the end of the file.

On machines that don’t have CALib but need to display Part objects in their content, the standard look for “NoPart” should be used. This is what OpenDoc displays when an editor for a particular part isn’t available. In the case of CALib applications, it works for when CALib isn’t available, as well.

Making your CALib-based documents work on machines with or without CALib takes a bit of extra coding, but from a version control standpoint, it is well worth it. Documents can go anywhere. A CALib document can be given to someone without CALib. That this person can actually edit the native content of the document, and then give the document back to you, is pretty nifty.

On machines where CALib isn’t available, users obviously won’t be able to add any new parts to the document. They will be restricted to editing the native content. However, this may include moving part objects around that someone else was nice enough to put in the document. This works. Remember that the geometry information is stored in the native objects, which all users can edit. The proxy part doesn’t handle the geometry. In addition, the user can delete the Part objects (which are displayed using the “No Part” look). This of course means that there is data orphaned in the Bento stream. (Since the user doesn’t have CALib, there is no way their machine can modify the Bento stream.) Fortunately, the stream will be compacted the next time the document is saved on a machine with CALib.

With some extra work, you can even allow the user to resize the Part objects without CALib. When this occurs, the information in the Bento stream for that part is no longer up to date. The native content object will need to be flagged as having been resized. When the document is opened on a machine with CALib, these objects will need to have their frame information renegotiated and resolved to reflect their new size.

We’ve been discussing types of editing that can still occur to a CALib document Part object when CALib isn’t available. There are, of course, edits that can’t be performed. Here are two:

1. Dragging that includes a Part object. Streaming the drag data must include streaming the Bento information into the flavor. This can’t be done without CALib. All that’s in the native object is a persistent reference to somewhere inside the Bento stream. You can’t resolve the reference without CALib.

2. Copying the object. At first, it would seem that you would just copy the native content object. It has a persistent reference. Both copies of the object would then point to the same Bento information, i.e., the part. This is a bad thing. When opened again on a CALib machine, each copy of the part should be independent of the other. (You could flag the copy as an unresolved copy, and then clone the object when the document is next opened on a CALib machine.)

As you can see from this discussion, CALib can be used to add OpenDoc capability to your existing applications without radically changing the way they work. The actual amount of code added to an application isn’t all that bad, either. Of course, this will vary, depending on architecture and document content, but most likely, it’s not a complete recode with major modifications throughout your application. Look for the latest CALib and CASample sample code on the OpenDoc DR4 release.

Have fun out there!

 

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.