TweetFollow Us on Twitter

Bedrock Intro
Volume Number:9
Issue Number:7
Column Tag:New Technologies

Introducing Bedrock

No it’s not Fred Flintstone, but it is at least as important as Fred is to developers!

By Patrick Rigney, Director of Core Technology, Symantec Corporation

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks. These Bedrock samples and headers are not listed here.

Over the past decade, a number of Graphical User Interfaces (GUIs) have become popular in desktop and workstation computing. On PCs the most notable GUIs are Apple’s Macintosh System Software and Microsoft’s Windows.

As the demand for GUI-based applications has increased, so has their complexity. Users demand powerful functionality, access to the latest operating system and hardware features, and What You See Is What You Get (WYSIWYG) editing. For developers, the GUIs’ Application Program Interfaces (APIs) present a broad range of functionality, a substantial portion of which must be learned to build such complex applications. Applications that were once small and manageable by one or a small number of engineers now require a larger team. Software developers are searching for solutions to these problems.

ENTER BEDROCK

Bedrock is a library of C++ classes and tools that provide a toolkit and an object-oriented application framework. An application framework is a skeleton application that contains functionality common to most applications. The developer builds an application on top of this framework.

Bedrock’s mission is to reduce the time and effort spent on many complex yet common cross-platform issues, and to provide simpler interfaces to system features (such as the Clipboard and AppleEvents), allowing more time to be spent on quality, maintainability, or additional features that make the application stand out.

Many of Bedrock’s classes are designed to hide implementation details of the target platform from the application. In effect, Bedrock acts a translator between the application and the Macintosh and Windows systems, taking high-level requests and invoking the appropriate forms for each platform. While Bedrock hides these issues, it still allows the developer free access to them when necessary. Application code written on top of Bedrock can coexist with code written directly to the platform.

Bedrock also provides classes and methods for features specific to individual platforms. This points out another major goal of Bedrock: to provide simplified interfaces to complex system functionality. Without these, Bedrock would be reduced to a “least common denominator” solution.

A LAYER- AND COMPONENT-BASED DESIGN

The Bedrock design allows the developer to use pieces that best suit the application’s needs. Conceptually, Bedrock’s classes are segregated into four layers, each of which contains various components. A component is an abstraction that contains one or more C++ classes and provides a related set of capabilities.

The architecture is layered to organize the information flow between layers. The components of an upper layer request services from and depend upon the lower layers, but components in the lower layers do not call components in the layers above them. Figure 1 shows a sampling of the major components in their parent layers.

Figure 1. Bedrock Layers

This layer-and-component architecture actually makes Bedrock appear and function like many small class libraries, rather than one large one. The relationships between layers and components are more formal and distinct, as opposed to the Microsoft Foundation Classes (MFC) and Apple’s MacApp, in which most classes are derived from a single root class. This makes the framework easier to learn, and more scalable.

THE APPLICATION FRAMEWORK LAYER

When using Bedrock, much of the programming time is devoted to building on top of classes in the Application Framework layer. This layer contains the Application, Document, Clipboard, and Chore components, which are highly interdependent. For example, if the developer changes the way the document component works, this application component will likely also need to be changed.

The Application

Bedrock’s Application component provides the structure of functionality common to most GUI applications, including support for application-level menu items in the File, Edit, and Help menus, the Apple menu on the Macintosh platform, and managing undo/redo of tasks. The Application component depends on the GUI Layer of Bedrock to dispatch events and provide the user interface, and on the Document component to control windows and the user’s access to data.

The Document

The application framework model of Bedrock has been strongly influenced by the Macintosh and Windows document architectures. The document is responsible for directing the interaction between the data and the user’s view of that data. It supports document-level commands in the File, Edit, and Help menus, printing, undoing of commands, and multiple open documents.

Clipboard and Scrap

The Bedrock clipboard is closely tied to the document. The document creates a scrap object, which is copied to the clipboard. The scrap object knows what formats it can translate to and from, and knows how to install a view in the Clipboard window to view the current contents of the clipboard.

Bedrock supplies some common scrap objects, including a text object, a Macintosh PICT object, and a Windows MetaFile object. This functionality is extended by providing a scrap object that knows how to deal with new data types.

Chores

Chores are tasks that are performed at various times in the application. Bedrock provides an implementation for the following kinds of chores:

• Timer chores-executed at a regular intervals, specified at creation time.

• Idle chores-performed whenever the application is not performing any other tasks.

• Urgent chores-performed immediately, whenever they are assigned.

Chores can be used in limited circumstances to simulate multi-threading.

Actions

Actions are typically created in response to events, such as choosing the “Cut” command from the Edit menu. They provide basic protocol and interfaces for managing changes to the document’s data. The application object can track the last action committed and will direct it to undo in response to a user’s “Undo” command.

A mouse action is created in response to a mouse button press. The mouse action object continues to exist, providing such functions as visual feedback, until the user releases the button.

An action informs the application whether it is undoable and should be tracked, because some actions are normally not considered undoable (e.g. saving a file or resizing a window).

THE GUI LAYER

Besides the all-important concept of the Application Framework layer, Bedrock provides a layer to handle the GUI. The components in this layer include Event Handling, Menus, Views, Windows, Controls, Cursors, Carets, Icons, and Drag/Drop.

Event Handling

A characteristic of modern event-driven systems is that users can choose to take any of several actions at any one time. These actions, which are typically menu choices, button selections, and keystrokes, result in the generation of operating system events. Procedural applications typically trap the event and take action on it based upon a switch statement somewhere in the event dispatching loop.

System events trigger the creation of a Bedrock event object, which is dispatched to an event-handling object. Every event-handling object has a supervisor, which is also an event handler. The supervisor is specified when the event handler is instantiated. If an event handler does not wish to handle an event, it passes it on to its supervisor.

Behaviors are objects that can be associated with an event-handling object at runtime. They may be associated with a particular instance of an object, or an entire class of objects. When an event is dispatched to an event handler, Bedrock first looks to see if an instance or class behavior can handle the event, before looking at the static event handling methods. This mechanism provides a way to add or change event responses at runtime. For example, a behavior can be added to a button that allows it to be dragged when clicked, as opposed to the normal “execute command” behavior associated with buttons.

The highest-level event handler in Bedrock is the application object, which supervises the application desktop and the event handlers for dialogs.

Views

Every object that can appear on the screen (with the exception of some menu objects) is drawn within a view. As the highest level visible object, views have the following properties:

• Are contained in a visual hierarchy,

• Can be hidden, shown, resized and clipped,

• Can be enabled or disabled,

• Can receive the focus, and it can receive mouse clicks and keyboard events,

• Can change background color,

• Can change cursor shape as the mouse passes over it,

• Have a local coordinate system.

Every view has an enclosure, which is another view that usually encompasses every visual point of the enclosed view. An enclosure always owns all of its enclosed views. This enclosure relationship results in a runtime hierarchy referred to as the visual hierarchy. The application desktop is at the top of this hierarchy, and typically encloses one or more windows. In turn, the windows enclose one or more views. Bedrock uses this hierarchy to dispatch mouse events to views and to handle activation/deactivation of views.

A scroller is a special class of view that can be used when the visual representation of data is larger than the allotted visual area. The scroller knows how to scroll its enclosed subviews in response to the user’s actions; conversely, these subviews do not need to know how to scroll. Scrollers are typically associated with scrollbars, and manage all interaction with them. Scrollers also manage scrolling via autoscrolling (that is, dragging the mouse) and the keyboard (for example, Home, End, Page Up, and Page Down keys).

Canvases

Bedrock renders views on a canvas. There are four major canvases in Bedrock: window, printer, metafile, and bitmap. Each implements a common rendering interface, allowing a view to be drawn on either a window or a printer by merely switching the target canvas and telling the view to draw itself.

Each canvas also implements specific behavior for its type. For example, windows can be tiled, cascaded, iconized, and obscured by other windows. Bitmaps and metafiles can be in-memory or disk-based.

Controls

Controls in Bedrock are views that encapsulate the platform’s native controls, so the buttons look like Macintosh buttons on the Macintosh and Windows buttons under Windows.

Bedrock provides scroll bars, buttons, checkboxes (including tri-state checkboxes), radio buttons, push buttons, group boxes, static text controls, edit controls, and list boxes.

Dialogs

Dialogs consist of a dialog box, a director, and one or more subviews (typically controls). The appearance of a dialog conforms to the GUI standards for the platform. Bedrock supports Modal and Modeless dialogs on both platforms, and Application Modal dialogs on Windows.

A director acts as the mediator between controls. For example, a director may enable the “Open” button on a dialog in response to a file name selection in a list box. In addition, directors handle keyboard navigation and default button presses.

Bedrock provides the following dialogs:

• Color Selection

• Open File

• Save File

• Confirm File-Close

• Confirm File-Revert

• Font Selection

• Printer Setup

• Print Job Initiate

• Print Job Progress/Status

Menus

Bedrock allows the developer to create multiple menu bars, and alternate between them by sending messages to the desktop.

Bedrock supports pull-down , pop-up , bitmap and custom-drawn menus. Each menu can have other menus added to it, or removed from it, as well as have individual menu items added. Menus and menu items can also be enabled and disabled (with appropriate highlighting changes occurring automatically).

Text Editing

Bedrock supplies basic text-editing capabilities. This component is useful mainly in the context of controls containing editable text.

Cursors, Carets, and Icons

Every view has a cursor associated with it. The cursor associated with the view will be displayed whenever the mouse is positioned over a visible region of the view. The application can create any number of cursors, but only one may be associated with a view at a given time.

A caret (usually marked with an I-beam cursor) marks the current insertion point in text. Bedrock provides the caret in its default text-editing services, and provides methods for setting the caret in a text view.

Icons are one of the significant characteristics of a GUI. Bedrock provides support for loading icons from resources and displaying them in a view.

Drag-and-Drop Support

Drag-and-Drop is the ability to drag “objects” (data) between locations. A good example of this is in the Macintosh Finder, which allows the user to delete a file by dragging its icon to the Trash.

Bedrock fully supports the Drag-and-Drop feature, both within an application (between views) and between applications, on both platforms.

THE OPERATING SYSTEM LAYER

Bedrock provides basic components that help hide the underlying operating system from the application. At this layer, the application will normally be using the services that Bedrock provides, with little subclassing or overriding.

Components in this layer include Graphics Support, System Configuration, Memory Management, Files, and Resources.

Graphics support

Bedrock supports platform-independent drawing with the following primitives: Line, Polyline, Rectangle, Rounded Rectangle, Region, Ellipse, Chord, Pie, Arc, Bitmap, Picture (Macintosh PICT and Windows MetaFile), Icon, and Text.

Bedrock also provides a logical coordinate system that supports translation and scaling. By default, Bedrock’s coordinate system defines the origin as the top left corner of the view. The coordinate system can easily be changed as necessary. to accommodate, for example, Cartesian coordinates with the origin at the bottom left. In addition, it is possible to independently transform and scale the x and y axes.

System Configuration

The system configuration abstraction provides information about the system upon which the Bedrock application is being run. Thus, the application can request system-wide (as opposed to application-specific) attributes and actions, such as current directory, screen resolution, or (on the Macintosh) hardware configuration flags (Macintosh Gestalt information).

Memory Management

Bedrock provides a general-purpose allocation scheme that shields the developer from the details of managing memory across platforms. Bedrock’s allocator requests large blocks from the system and suballocates them on demand to the application. When freed by the application, adjacent free blocks are coalesced in to larger blocks.

Bedrock objects are pointer-based. Handle-based objects are not supported.

Files

The Bedrock file components provide platform-independent file I/O and uniform handling of errors. The FileAccess component is extensible to allow network- or memory-based random access to data.

Resources

Most applications use resources to store small pieces of code or data that can be changed without recompiling the application. For example, all strings used by an application can be stored in resources for easy localization.

Bedrock supplies tools to improve the portability of resources. The Bedrock Resource Compiler (BEDRC) takes resources defined in Bedrock resource statements and compiles them into the native resources of the platform. The Bedrock Resource Language syntax is an extension of Apple’s Rez language, adding type declaration (typedef statements) and complex type creation (struct, class, union). The syntax is C++ compatible, and the compiler supports the ANSI C preprocessor directives, allowing it to read and derive type information directly from C++ header files. The developer can then use these new types in resources.

Bedrock’s resource mechanism allows the application to instantiate objects by name from a resource definition. For example, a view hierarchy may be defined in a Bedrock resource, and later be instantiated by name from the resource file. By modifying the resource file, users can modify the view hierarchy without recompiling the application.

THE FOUNDATION LAYER

Bedrock’s Foundation Layer provides basic services to the higher layers, or directly to application code. The components at this level are largely independent of one another. The Foundation Layer components, in turn, depend only upon the facilities of the C++ language. These components include Streams, Sinks, Strings, Collections, Exceptions, and International support.

Streams and Sinks

Streams provide a generalized interface for reading and writing data, including protocol for higher-level entities (integers, floats, strings, and so on), and thus provide platform- and device-independence for all kinds of I/O. Streams are generally heterogeneous; that is, they operate on many types of data.

Streams read from and write to sinks. A sink is a “device” that can be a source or destination for a stream of bytes. Sinks provide only a byte-oriented, untyped interface. Bedrock provides file sinks and memory block (resizable and nonresizable) sinks. Sinks may be extended to construct, for example, serial interface sinks and network interface sinks.

Strings

A string is a run of text, composed of characters. Strings always use characters as the units of transfer, so type-safety is guaranteed and access is fast and efficient. Bedrock stores characters in Unicode format, and provides ways to export characters to other character systems such as ASCII.

International Support

Bedrock provides support for localization through resources (as discussed earlier), writing systems, and locales.

A writing system encompasses all the information a Bedrock application needs to edit, display, store, and retrieve text strings. It depends on the locale abstraction to supply basic information such as date format, thousands separator, and so on.

Together, the writing system and the locale track and implement script properties, sort orders, word-breaking and boundary behavior, mapping and translation tables, and formatting for times, dates, and numbers.

Data Structures and Collections

Bedrock’s collections are a subset of the Rational C++ Booch Components, consisting of Collection, Ordered Collection, Map (a dictionary of domain/range pairs), Queue, Stack, and Tree.

Tools and iterators are used to act on a collection. Bedrock includes tools for searching and sorting collections.

Collections, tools and iterators are implemented using C++ templates, and can therefore store and operate on any data type, rather than just objects.

Exception Handling

The components in each layer detect errors that the application must handle. In those cases where the library does not know how to handle an error, it can throw an exception object. The application can catch this object and respond.

Bedrock’s exception handling is based on that described in The C++ Programming Language and The Annotated C++ Reference Manual (ARM). The Bedrock Exception Library (BEL) is included to emulate this mechanism on compilers that do not support ARM Exception Handling. BEL’s syntax is slightly different from the ARM syntax, but is designed to easily translate to that syntax. When using a compiler that supports C++ exceptions, one can remove the BEL emulation.

BROAD RANGE OF FUNCTIONALITY

Bedrock’s varied components provide a broad range of functionality to the application developer. Complexity in the framework is reduced by layering the components, which helps organize their interactions. Within the layers, each component acts as a class library in itself, making the entire system easier to learn and use.

By combining this architecture with the general benefits of object oriented programming, Bedrock provides cross-platform capabilities and simplifies the interface to system features (both cross-platform and platform-specific). The developer using Bedrock can more quickly deliver high-quality applications on both the Macintosh and Windows.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Combo Quest (Games)
Combo Quest 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: Combo Quest is an epic, time tap role-playing adventure. In this unique masterpiece, you are a knight on a heroic quest to retrieve... | Read more »
Hero Emblems (Games)
Hero Emblems 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: ** 25% OFF for a limited time to celebrate the release ** ** Note for iPhone 6 user: If it doesn't run fullscreen on your device... | Read more »
Puzzle Blitz (Games)
Puzzle Blitz 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Puzzle Blitz is a frantic puzzle solving race against the clock! Solve as many puzzles as you can, before time runs out! You have... | Read more »
Sky Patrol (Games)
Sky Patrol 1.0.1 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.1 (iTunes) Description: 'Strategic Twist On The Classic Shooter Genre' - Indie Game Mag... | Read more »
The Princess Bride - The Official Game...
The Princess Bride - The Official Game 1.1 Device: iOS Universal Category: Games Price: $3.99, Version: 1.1 (iTunes) Description: An epic game based on the beloved classic movie? Inconceivable! Play the world of The Princess Bride... | Read more »
Frozen Synapse (Games)
Frozen Synapse 1.0 Device: iOS iPhone Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Frozen Synapse is a multi-award-winning tactical game. (Full cross-play with desktop and tablet versions) 9/10 Edge 9/10 Eurogamer... | Read more »
Space Marshals (Games)
Space Marshals 1.0.1 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.1 (iTunes) Description: ### IMPORTANT ### Please note that iPhone 4 is not supported. Space Marshals is a Sci-fi Wild West adventure taking place... | Read more »
Battle Slimes (Games)
Battle Slimes 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: BATTLE SLIMES is a fun local multiplayer game. Control speedy & bouncy slime blobs as you compete with friends and family.... | Read more »
Spectrum - 3D Avenue (Games)
Spectrum - 3D Avenue 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: "Spectrum is a pretty cool take on twitchy/reaction-based gameplay with enough complexity and style to stand out from the... | Read more »
Drop Wizard (Games)
Drop Wizard 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Bring back the joy of arcade games! Drop Wizard is an action arcade game where you play as Teo, a wizard on a quest to save his... | Read more »

Price Scanner via MacPrices.net

14-inch M4 Pro/M4 Max MacBook Pros on sale th...
Don’t pay full price! Get a new 14″ MacBook Pro with an M4 Pro or M4 Max CPU for up to $320 off Apple’s MSRP this weekend at these retailers…they are the lowest prices available for these MacBook... Read more
Get a 15-inch M4 MacBook Air for $150 off App...
A couple of Apple retailers are offering $150 discounts on new 15″ M4 MacBook Airs this weekend. Prices at these retailers start at $1049: (1): Amazon has new 15″ M4 MacBook Airs on sale for $150 off... Read more
Unreal Mobile is offering a $100 discount on...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 13, and SE phones... Read more
16-inch M4 Pro MacBook Pros on sale for $250-...
Don’t pay full price! Amazon has 16-inch M4 Pro MacBook Pros (Silver or Black colors) on sale right now for up to $300 off Apple’s MSRP. Shipping is free. These are the lowest prices currently... Read more
Get a 14-inch M4 MacBook Pro for up to $240 o...
Amazon is offering a $150-$250 discount on Apple’s 14-inch M4 MacBook Pros right now. Shipping is free. Be sure to select Amazon as the seller, rather than a third-party seller: – 14″ M4 MacBook Pro... Read more
Clearance 14-inch M3 Pro MacBook Pros availab...
B&H Photo has clearance 14″ M3 Pro MacBook Pros (in Black or Silver) on sale for $500 off original MSRP, only $1499. B&H offers free 1-2 day delivery to most US addresses: – 14″ 11-Core M3... Read more
Sams Club is offering a $50 discount on Titan...
Sams Club has Titanium Apple Watch Series 10 models on sale for $50 off Apple’s MSRP. Sams Club Membership required. Note that sale prices are for online orders only, in-store prices may vary. Choose... Read more
Sunday Sale: Apple’s latest 13-inch M4 MacBoo...
Amazon has new 13″ M4 MacBook Airs on sale for $150 off MSRP right now, starting at $849. Sale prices apply to most colors and configurations. Be sure to select Amazon as the seller, rather than a... Read more
Apple’s M4 Mac minis on sale for record-low p...
B&H Photo has M4 and M4 Pro Mac minis in stock and on sale right now for up to $150 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses. Prices start at only $469: – M4... Read more
Week’s Best Deals: 14-inch M4 MacBook Pros fo...
Don’t pay full price! These retailers are offering $200-$250 discounts on new 14-inch M4 MacBook Pros this week…they are the lowest sale prices available for new MacBook Pros: (1): Amazon is offering... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.