Important: The information in this document is obsolete and should not be used for new development.
Recipes--Windows
The recipes and sample code in this section demonstrate how to create a window from a'View'
resource and how to define and use floating windows in your application.Recipe--Creating a Window From a View Resource
To create a window from a view resource, you perform these steps:
The sample code shown in this recipe is from the DemoDialogs application.
- Define a resource ID constant for the
'View'
resource.- Define the
'View'
resource for the window.- Call the
gViewServer->NewTemplateWindow
method to create a window from the'View'
resource.
Define a Resource ID Constant for the 'View' Resource
The DemoDialogs application defines a resource ID for the "Views by Template" view in both its resource definition file and implementation file. In the resource file,DemoDialogs.r
, the ID is defined as
#define cTemplateViews1002In the implementation file,UDemoDialogs.cp
, the ID is defined as a constant:
const short cTemplateViews = 1002;Define the 'View' Resource for the Window
You may choose to define a view resource with a view resource editor that creates a compiled resource, then use aninclude
statement to include the compiled resource into your resource definition file. Or you can convert the compiled resource to text with a resource decompiler and add the text definition to your resource file. This is the approach used in the DemoDialogs application. (For more information on resource formats, see "Converting Between Resource Formats," beginning on page 427.)The Dialogs menu in the DemoDialogs application contains the Views by Templates command, which creates a window that displays many types of MacApp views. DemoDialogs stores the view hierarchy for this window in a text
'View'
resource definition in the fileDemoDialogs.r
. A portion of that resource, including the window definition but not the definitions for all of the enclosed views, is shown on the following page.
resource 'View' (cTemplateViews, purgeable) { MAThreeOh, { ViewSignatureAndClassname { 'wind', 1862, "", noID, enabled, noIdle, {}, MAThreeOh, {50, 20}, {260, 430}, sizeVariable, sizeVariable, shown, doesntWantToBeTarget, handlesCursor, letsSubViewsHandleCursor, noCursorID, handlesHelp, letsSubViewsHandleHelp, noHelpID, 1, NoDrawingEnvironment {}, AdornerListSignatureAndClassname { noIdentifier, AdornerList, AdornerElementSize, AdornerElementSizeShift, DynamicArrayAllocationIncrement, { AdornFirst, AdornerLocalObject {EraseAdorner}, DrawView, AdornerLocalObject {DrawAdorner}, AdornLast, AdornerLocalObject {ResizeIconAdorner} } }, emptyUserArea, Window { zoomDocProc, 'DLOG', goAwayBox, resizable, doFirstClick, freeOnClosing, disposeOnFree, closesDocument, openWithDocument, dontAdaptToScreen, stagger, forceOnScreen, dontCenter, doesntFloat, doesntHideOnSuspend, generateActivates, filler, kWindowTitles, 2 }, 3 }, . // Other views not shown. . . } }Create a Window From the 'View' Resource
Once you have defined a view resource for your window and a resource ID constant to identify it, you can create the window using MacApp's global view server object. (The global view server is described in "The TViewServer Class," beginning on page 218.) In itsTTestApplication::MakeTemplateViews
method, the DemoDialogs application callsgViewServer->NewTemplateWindow
, passing a command number as the resource ID:
aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL); FailNIL(aWindow); // Some code not shown. aWindow->Open();For the "Views by Template" menu command, the variable aCommandNumber has the value cTemplateViews.MakeTemplateViews
calls the window's Open method to display the window.Recipe--Defining and Using a Floating Window
The Dialogs menu of the DemoDialogs application has a menu command called Message Windoid. Each time a user chooses Message Windoid, the application opens a small floating window with a title bar, close box, static text view, and text edit view. The window is always drawn in front of other application windows (except other copies of itself) and is hidden when the application is switched to the background.The floating window also demonstrates drag and drop--its static text can be dragged, any selected text in the text edit view can be dragged, and dragged text can be dropped in the text edit view.
To define and use a floating window in your application, you perform these steps:
The sample code shown in this recipe is from the DemoDialogs application.
- Include MacApp's
FloatWindow.r
file into your resource definition file.- Call the
InitUFloatWindow
initialization method.- Base your floating windows on the
TFloatWindow
class or a subclass.- Define a resource ID for the
'View'
resource.- Use the
'fwnd'
resource type to define a floating window'View'
resource.- Call
NewTemplateWindow
to create the floating window.
Include MacApp's FloatWindow.r File Into Your Resource File
MacApp supplies floating window information your application needs in the fileFloatWindow.r
. DemoDialogs includes that information into its resource definition file,DemoDialogs.r
, with the following code:
#ifndef __FloatWindow__ #include "FloatWindow.r" #endifCall the InitUFloatWindow Initialization Method
To initialize MacApp's floating window support, your application must call theInitUFloatWindow routine. The DemoDialogs application calls InitUFloatWindow from its main routine:
InitUFloatWindow();Base Your Floating Windows on the TFloatWindow Class
TheTFloatWindow
class is described in "Floating Windows," beginning on page 448. To take advantage of MacApp's floating window support, your floating window objects should be based on this class or on a subclass you define.Define a Resource ID for the 'View' Resource
The DemoDialogs application defines a resource ID for the Message Windoid view in both its resource definition file and implementation file. In the resource file,DemoDialogs.r
, the ID is defined as
#define cMessageWindoid1014In the implementation file,UDemoDialogs.cp
, the ID is defined as a constant:
const short cMessageWindoid = 1014;Use the 'fwnd' Resource Type to Define a Floating Window Resource
Working with view resources is described in detail in "Working With View Resource Templates," beginning on page 425. An example is also provided in "Recipe--Creating a Window From a View Resource," beginning on page 451.As with other window and view resources, you can use a view-editing application to create a floating window resource. You can include the output, a compiled resource definition, into your resource definition file, or you can use a resource decompiler such as DeRez to convert the compiled resource to its text equivalent. You can then paste the text version into your resource definition file.
The DemoDialogs application defines the view resource for its Message Windoid window in the file
DemoDialogs.r
. A portion of that definition is shown here:
resource 'View' (cMessageWindoid, purgeable) {MAThreeOh, { ViewSignatureAndClassname { 'fwnd', 430, "", 'WIND', enabled, noIdle, {}, MAThreeOh, {72, 64}, {55, 364}, sizeVariable, sizeVariable, shown, doesntWantToBeTarget, handlesCursor, letsSubViewsHandleCursor, noCursorID, handlesHelp, letsSubViewsHandleHelp, noHelpID, 1, NoDrawingEnvironment {}, AdornerListSignatureAndClassname { noIdentifier, AdornerList, AdornerElementSize, AdornerElementSizeShift, DynamicArrayAllocationIncrement, { AdornFirst, AdornerLocalObject {EraseAdorner}, DrawView, AdornerLocalObject {DrawAdorner} } }, emptyUserArea, FloatWindow { kSystem75_kWindoidWDEF, 'mark', goAwayBox, notResizable, doFirstClick, freeOnClosing, disposeOnFree, closesDocument, openWithDocument, dontAdaptToScreen, dontStagger, forceOnScreen, centerHorizontally, floats, hidesOnSuspend, doesntGenerateActivates, filler, kWindowTitles, -1 }, 2 }, ... // Some information not shown. }Call NewTemplateWindow to Create a Floating Window
The DemoDialogs application uses theMakeDialog
method to create various windows, including the Message Windoid window.MakeDialog
includes the following lines to create and open the floating window:
TWindow *aWindow; aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL); FailNIL((aWindow); aWindow->Open();The resource ID is passed toMakeDialog
as a command number, so for the Message Windoid menu command, the variable aCommandNumber has the value cMessageWindoid, and NewTemplateWindow creates a Message Windoid floating window.