[ZooLib home] [info@zoolib.org]

ZHelloWorld

This simple application creates a window containing a ZCaptionPane that says "Hello World!" and has a File menu that allows you to quit. There's also an "About ZHelloWorld" menu item that is presently unimplented but demonstrates handling the little differences between platforms (putting the About item in the Apple menu on the MacOS vs. the Help menu on other platforms). Note that while ZHelloWorld builds on POSIX and a sample binary is provided for Linux, as yet we have no XWindows menu bar widget and so ZHelloWorld isn't completely functional. We suggest you don't run it in the background when you launch it under X, so you can kill it with Control-C.

Browse the Source Code Online

zconfig.h
Set app-specific options (potentially build-specific ones) and include the zlib-provided config headers

ZHelloWorld.pch
Metrowerks precompiled header source - this includes ZPCH.h, which sets up the precompiled headers for the different builds. You can place #includes to app-specific precompiles here or just define things in here if you want.

Precompiled headers are only used when building ZooLib applications with Metrowerks Codewarrior. They could probably be made to work with other development environments that provide them, but we haven't tried.

ZHelloWorld.cpp

The OS-dependent applications and windows are members of the base classes - ZApp has ZOS_App and ZWindow has ZOS_Window

There's something unusual in zlib that you'll find in ZHelloWorldWindow. In zlib, ZSubPanes do not know their own coordinates; they ask their pane locator whenever their size, location and some other things are needed. This creates great flexibility in doing window layout and is very powerful, but I found it a little hard to wrap my head around. In our case, ZHelloWorldWindow is the ZPaneLocator for the HelloWorld caption, and just returns a fixed ZPoint.

In the more general case, I usually locate one pane in the top left corner, and then calculate the location of the other points by calling ZSubPane::GetLocation and ZSubPane::GetSize for nearby panes and adding offsets. Thus ZPaneLocator::GetPaneLocation might be called recursively, and locations update automatically if pane sizes change.

Andy Green usually makes the window act as the pane locator for all the items in it, but I've found it helpful to make some of the ZSuperPanes that contain other panes be locators so things can be broken down into more manageable units. For example, I have a toolbar pane that is the locator for all the buttons inside it, and a list pane that is the locator for the list item panes - the vertical location is calculated from the index and item height.

It is also possible to write either custom or general purpose ZPaneLocators that could be held as data members of a window or superpane, so you could implement any kind of layout manager in a readily reusable way. I've got plans to write a "ZRelativePaneLocator" where you can pass in pointers to the panes that a given pane is supposed to be next to, as well as how it's positioned relative to it.

ZHelloWorld_Res.inc
Compiler and os-independent resource file source. The file ZResourceDef.h sets up macros that define such things as ZSTRID, ZSTREND, ZBMPID and ZBMPEND in ways the result in building native resources for the resource compilers on each specific platform. Generally UI graphics are provided as BMP resources; ZLib has a basic BMP parser so you can read BMP's no matter what platform you're on.

ZHelloWorld_Res.r
ZHelloWorld_Res.rc
The platform-specific resource compiler source; they just include ZHelloWorld_Res.inc.

ZHelloWorld_ResID.h
Resource ID definitions for the text string and the BMP picture of Andy's new niece Amy.

[ZooLib home] [info@zoolib.org]