PreviousUsing GUIs from Third Party Tools Using Panels Version 2Next"

Chapter 19: Panels Version 2

Panels V2 is not available in UNIX environments.

Panels Version 2 (Panels V2) is a run-time module which enables your program to have a sophisticated graphical user interface. Simple calls to Panels V2 mean that you need no knowledge of the environment API . The user interface can also be ported between different graphical environments without alteration . Panels V2 is supplied with a comprehensive on-line reference in addition to the information given here.

19.1 Overview

Panels Version 2 (Panels V2) enables your application to have a graphical user interface (GUI), without the need for you to know how to program the API of the graphical environment you are working in. Your application simply calls Panels V2 with generic instructions about the action needed, and Panels V2 translates them into the correct form for the environment.

This not only simplifies programming, but also means you can use exactly the same source program in a number of different environments: the correct version of Panels V2 is used automatically at run time. Panels V2 gives you the nearest approximation available in the environment, including a GUI Emulation on DOS and OS/2 when only character mode is available.

When a call from your application requests it, Panels V2:

You can also sound the bell and control Panels V2 itself.

Panels V2 provides a wide range of graphical objects, such as windows, pulldown menus, push buttons and icons. The objects are typical of whatever environment is in use. For example, in a Presentation Manager environment under OS/2, Panels V2 provides CUA objects with their characteristic behaviors.

Associated with each type of object are:

To help you write your application, Panels V2 comes with a copyfile, pan2link.cpy, which contains all the record definitions. This file also contains convenient mnemonics (78 level data items) which represent numerical codes indicating:

19.2 Operation

Panels V2 provides a user interface for your application. It has no user interface itself: you have to write an application which makes calls to it and gives it instructions about what to do. See section Using Panels V2 for a broad outline of what your application has to do. Further sections outline other important concepts and facts concerning Panels V2.

19.2.1 Using Panels V2

In order to use Panels V2 to provide its user interface, your program needs to contain the following:

  1. The copyfile pan2link.cpy (supplied) in the Data Division Working-Storage Section.

    This contains record definitions and mnemonics (78 level items) for numeric codes. You can use the COPY statement to include this file in your program. See your Language Reference for information on the COPY statement.

  2. An initialization call to Panels V2 to register your application with it.

    This call returns some information, such as the current environment.

    All calls to Panels V2 follow a similar pattern: Panels V2 carries out the instructions you give it, and then returns control to your application. See the section The Call Interface for a description of how to make a call to Panels V2.

    You might want to process some of the information you have received back from the initialization. For instance, depending on the environment which Panels V2 tells you it is operating in, you can arrange to specify object sizes in units of pixels or characters.

  3. Calls to Panels V2 with instructions to create and display graphical and text objects on the screen. Each call specifies the function that you want Panels V2 to carry out and passes records containing the parameters for the function.

    When you have shown the initial windows and objects via Panels V2, you need to find out if the user is giving the application any input, and respond accordingly.

  4. A call to Panels V2 requesting the next event from the event queue, sending the event record contained in pan2link.cpy for the reply.

    You can instruct Panels V2 not to come back until there is an event or a certain time has elapsed, or to come back immediately.

  5. Code to process the returned event record.

    Take advantage of the implied tree structure of the information in this record to structure your program into sections dealing with different kinds of events and different kinds of objects.

    Each event conveys an elementary piece of information such as "the keyboard focus has been set on window reference XXXX". Be aware that several events may have occurred and queued up since you last called Panels V2. You may want to ignore some of them.

  6. One or more calls to Panels V2 to respond.

    If the event signals to your program that some action is needed at the interface, such as displaying a dialog box, you need to call Panels V2 to do this. Each separate function, such as sounding the bell, moving the position of a scroll bar slider or scrolling text in a window, requires a separate call. You can change the appearance of the user interface dynamically during the session, for example by renaming a menu option or button depending on previous history.

  7. A call to terminate Panels V2 when the session is finished.

    This releases the resources which were allocated to it, and removes any Panels V2 objects from the screen.

Steps 4 through 6 will be carried out many, many times during the execution of a typical application. This implies that your program will likely contain some kind of event processing loop.

19.2.2 The Call Interface

When your application wants to start, control, interrogate or terminate Panels V2, it calls Panels V2, passing one or more records.

The exact form of the syntax is shown in the On-line Reference with each function, but the general form is:

call "panels2" using P2-Parameter-Block

The first record is always P2-Parameter-Block. Your application needs to write information to it to tell Panels V2 basic information such as which function is requested. When the call returns, it contains information such as the success or otherwise of the call.

The second record depends on the object to which the function relates. When the function requests the next event in the queue, which could be from any object, a universal record P2E-Parameter-Block is sent.

If Panels V2 needs more information to carry out the function - for instance, you are modifying an object, or making an interrogation which is not completely defined by the data items in P2-Parameter-Block , your application needs to write to the appropriate data items before making the call.

Certain functions need further records containing text and or attributes, shown as text-buffer and attribute-buffer. These records are not supplied with Panels V2 and must be defined in the Working-Storage Section of your program.

When the call returns, the object record contains information which your application can process. Even if the function was a controlling function rather than an interrogating one, it may return information. See the individual function for details.

19.2.3 Records

Every time your application calls Panels V2, it passes one or more records to it, which are passed back when the call returns. Both your program and Panels V2 can read and write to them. The definitions for all these records are contained in pan2link.cpy , supplied with Panels V2 for inclusion in your application.

When you make a call to Panels V2 to create or modify something, you describe what you want to happen by assigning suitable values to data items first, then sending the record with the call.

When you make a call to Panels V2 to interrogate it, you pass the appropriate record to it in order that it can assign values to the data items. You can then interpret these values when it returns the record.

In some cases you can both send and receive the information you want on a single call.

The interface to Panels V2 uses the following records:

The main record: P2-Parameter-Block
The events record: P2E-Parameter-Block
Object Records: P2A-Accelerator-Record

In addition, a text buffer and/or attribute buffer can be specified where an object uses some text and/or attributes.

19.2.4 Functions

Whenever your application calls Panels V2, it tells Panels V2 what it wants by means of a function code.

This function code is a numerical value sent in data item P2-Function of record P2-Parameter-Block. However, you do not need to remember or find out numerical codes, because each one has a mnemonic such as Pf-Create-Window so that you can use a statement such as:

move pf-create-window to p2-function.

Many functions are available, to create, modify, interrogate and delete the various types of objects (as appropriate), and request event information.

Some functions just require record P2-Parameter-Block to be sent with the call.

Depending on the function, you might need to pass more information, for example, the size and position of a window. You provide this by passing a further record. Each object type has its own record for this purpose, containing relevant parameters.

Some functions need a third record to carry text, and some a fourth to carry text attributes.

When the call returns, the records contain information about the success of the function, and possibly other details. For instance, if you tell Panels V2 to create a button making it big enough to contain the text label you specify, it tells you how big it actually made the button.

19.2.5 Events

Events signify any changes that happen at the user interface provided by Panels V2. They can be:

Each object has a range of associated events. For instance, a button can be clicked, a window can be sized, moved or closed. A single event conveys an elementary piece of information such as "the scroll bar slider has been moved and released at this position".

Whenever an event occurs, it is put into a first-in, first-out queue inside Panels V2. Your application has to request the next event in the queue by calling Panels V2. Since it is not possible to predict what object may have experienced the event, a universal event record, P2E-Parameter-Block, is sent with the call to collect the information.

Depending on the values returned in some data items in P2-Event-Record, your application needs to interpret other parts of the record in a particular way. This allows the application to use a tree-search method to find out which event has occurred.


P2E-Parameter-Block is returned to your application after a call to return the next event from the event queue.

The application evaluates data-item P2E-Event-Type and finds that it is set to P2E-Gadget-Event. This means that an event occurred, and the event was from a gadget.

Your application now has to determine what type of gadget caused the event. It evaluates P2E-Gadget-Type, finding that it is set to P2E-Button. This means that the gadget that caused the event was a button.

To find out what happened to the button, the application evaluates P2E-Gadget-Command and finds that it is set to P2E-BN-Clicked. This means that the button was clicked on.

P2E-BN-Clicked is not a unique numerical code. It has a value of 1, the same as events such as P2E-SB-Line-Up and P2E-LB-Cursor-Moved. However, your application is able to differentiate because it has evaluated P2E-Gadget-Type to find that the event is related to a button.

Your application could contain code similar to this:

 sort-events section.
* What sort of event has happened?
     evaluate p2e-event-type
       when p2e-gadget-event perform gadgets
       when < some other kind of event> ...

 gadgets section.
* What kind of gadget caused this event?
     evaluate p2e-gadget-type
       when p2e-button perform buttons
       when p2e-scroll-bar perform scrolls
       when < other kinds of gadget> ...

 buttons section.
* What happened to the button?
     evaluate p2e-gadget-command
       when p2e-bn-clicked perform button-click section
       when < other button events > ...

 scrolls section.
* What happened to the scroll bar?
     evaluate p2e-gadget-command
       when p2e-sb-line-up perform scroll-up section
       when < other scroll bar events > ... 

19.2.6 Error Codes

When any call comes back from Panels V2, a numerical status code is returned in data item P2-Status. This gives you information about what happened to the call; either that it was successful, or what went wrong.

Each status has a descriptive mnemonic by which it is known. You can substitute this mnemonic for the numerical status code in your program; they are defined in copyfile pan2err.cpy.

19.2.7 Accessing the On-line Reference Material

Panels Version 2 comes complete with detailed help and reference material on-line, so that you can access it quickly and easily when you need it. This is presented in the form of hypertext, so that you can search for a key word, click on key phrases (hot-spots) to get further information or follow up a line of enquiry, or make use of many other facilities which would not be available to you in a conventional book.

You can access this help in two ways:

In either case, a new window appears containing the help. If you are not sure how to use the help system, click on Help on the menu bar at the top of the window, and click on Help for Help in the pulldown menu to see instructions.

19.2.8 Files Required at Run Time

When your end user runs an application which uses Panels V2 to provide its user interface, the files appropriate to the environment (see Table 19-1 below) must be present. They should be located in a directory which is on both the operating system path and the COBDIR environment variable. Additionally, OS/2 .dll files must be in a directory specified by the LIBPATH environment variable.

Table 19-1: Files Required for Panels V2 at Run Time

GUI Emulation
Presentation Manager under OS/2
Microsoft Windows
Microsoft Windows NT
panels2.gnt panels2.gnt panels2.gnt panels2.gnt
coblib.dll and cobolapi.dll (under OS/2);
coblib.dle (under DOS)
coblib.dll coblib.dlw coblib.dlw
    cblwin.dll pan2nt.dll
    cblsseg.dll setpptr.dll
pan2chr.lbr pan2pm.dll
or pan2pm32.dll
pan2win.dll pcinst.gnt
adiskey.gnt   setpptr.dll,
panels.gnt   pcinst.dll,

19.2.9 Using Functions in More Than One Environment

Some environments do not support certain features, although Panels V2 allows you to use them where they are available. This table tells you about the availability of functions in different environments, so that you can ensure that your application is generic across environments where necessary. Environments shown are not necessarily supported at present.

Environments are shown as:

Table Heading
Emu The Graphical Emulation environment
PM Presentation Manager
Win Windows and Windows NT

Key to symbols in table:

Check (Y) The function is available in this environment.
Cross (x) The function is not available in this environment.
Asterisk (*) This function is available in this environment. However, there is some special consideration when using the function in this environment, and you should refer to the information for the specific function in the On-line Reference.

Table 19-2 : Environment Support for Functions

Function Environment
Emu PM Win
Pf-Add-Accelerator-Key x Y x
Pf-Add-Menu-Item * Y *
Pf-Add-Resource x Y Y
Pf-Allocate-Color x Y Y
Pf-Allocate-VC-Color x x Y
Pf-Alt-Origin-Offset Y Y Y
Pf-Amend-Text Y Y Y
Pf-Animate-Bitmap x Y Y
Pf-Arrange-MDI-Windows x x Y
Pf-Associate-Panel-Id x Y x
Pf-Attach-Icon x * *
Pf-Broadcast-Event Y Y Y
Pf-Change-Button-Style Y Y Y
Pf-Change-Entry-Field-Style Y Y *
Pf-Change-List-Box-Style x Y Y
Pf-Change-Sel-Box-Style Y Y *
Pf-Change-Window-Style Y Y *
Pf-Clipboard-Cancel-Read Y Y Y
Pf-Clipboard-Initiate-Read Y Y Y
Pf-Clipboard-Read Y Y Y
Pf-Convert-Native-To-Set x x Y
Pf-Convert-To-Native-Set x x Y
Pf-Copy-Selection-To-Clipboard x x Y
Pf-Create-Button * Y *
Pf-Create-Container Y Y Y
Pf-Create-Dialog-Box * Y Y
Pf-Create-Entry-Field * Y *
Pf-Create-Help-Instance x Y x
Pf-Create-Label Y Y Y
Pf-Create-List-Box * Y Y
Pf-Create-Notebook Y Y Y
Pf-Create-Popup-Menu x * Y
Pf-Create-Progress x Y Y
Pf-Create-Scroll-Bar * Y *
Pf-Create-Sel-Box * * *
Pf-Create-Standard-Button Y Y *
Pf-Create-Standard-Entry-Field * Y Y
Pf-Create-Standard-List-Box * Y Y
Pf-Create-Standard-Scroll-Bar * Y *
Pf-Create-Standard-Sel-Box Y Y *
Pf-Create-Standard-Window Y Y *
Pf-Create-VC x x Y
Pf-Create-Window * Y *
Pf-Cut-Selection-To-Clipboard x x Y
Pf-Delete-Accelerator-Key x Y x
Pf-Delete-Accelerator-Table x Y x
Pf-Delete-All-List-Box-Items Y Y Y
Pf-Delete-All-Sel-List-Items Y Y Y
Pf-Delete-Bitmap Y Y Y
Pf-Delete-Block x Y Y
Pf-Delete-Cursor Y Y Y
Pf-Delete-Dialog-Box Y Y Y
Pf-Delete-Gadget Y Y Y
Pf-Delete-Icon Y Y Y
Pf-Delete-List-Box-Item Y Y Y
Pf-Delete-Menu Y Y Y
Pf-Delete-Menu-Item Y Y Y
Pf-Delete-Sel-List-Item Y Y Y
Pf-Delete-Text Y Y Y
Pf-Delete-Window Y Y Y
Pf-Destroy-VC x x Y
Pf-Disable-Gadget Y Y Y
Pf-Disable-Windows-Shutdown x x Y
Pf-Display-Bitmap Y Y Y
Pf-Display-Colormap-Bitmap x * Y
Pf-Display-Icon * Y Y
Pf-Display-Popup-Menu x * *
Pf-Display-Text Y Y Y
Pf-Display-Text-In-Color Y Y Y
Pf-Draw-Group-Box Y Y Y
Pf-Enable-Gadget Y Y Y
Pf-Entry-Field-Border-Offset Y Y Y
Pf-Flush-Panel Y Y Y
Pf-Get-Ancestor Y Y Y
Pf-Get-Attribute-Info x Y Y
Pf-Get-Attributes x Y Y
Pf-Get-Button-Details Y Y Y
Pf-Get-Child-Objects Y Y Y
Pf-Get-Color x Y Y
Pf-Get-Cursor-Position Y Y Y
Pf-Get-Cursor-Style Y Y Y
Pf-Get-Device-Resolution * Y Y
Pf-Get-Entry-Field-Details Y Y Y
Pf-Get-Entry-Field-Text Y Y Y
Pf-Get-Environment-Info Y Y Y
Pf-Get-Event-No-Wait Y Y Y
Pf-Get-Event-With-Wait Y Y *
Pf-Get-Frame-Window-Offset Y Y Y
Pf-Get-Gadget-Handle-From-Id Y Y Y
Pf-Get-Gadget-Id-From-Handle Y Y Y
Pf-Get-Gadget-System-Handle x * *
Pf-Get-Group-Box-Details Y Y Y
Pf-Get-Group-Box-Origin Y Y Y
Pf-Get-Input-Focus Y Y Y
Pf-Get-Label-Text Y Y Y
Pf-Get-List-Box-Details Y Y Y
Pf-Get-List-Box-Item-Count Y Y Y
Pf-Get-List-Box-Item-State Y Y Y
Pf-Get-List-Box-Item-Text Y Y Y
Pf-Get-Menu-Item-Property Y Y Y
Pf-Get-Menu-Item-Text Y Y Y
Pf-Get-Mouse-Position Y Y Y
Pf-Get-Mouse-Shape * Y Y
Pf-Get-Mouse-State x Y Y
Pf-Get-Next-Selected-Item Y Y Y
Pf-Get-Object-Color x * Y
Pf-Get-Object-Flags Y Y Y
Pf-Get-Object-Procedure x Y Y
Pf-Get-Object-Type x Y Y
Pf-Get-Resource-Labels Y Y Y
Pf-Get-Scroll-Bar-Details Y Y Y
Pf-Get-Sel-Box-Details Y Y Y
Pf-Get-Sel-Box-Text Y Y Y
Pf-Get-Sel-List-Item-Text Y Y Y
Pf-Get-Shift-Lock-Key-States Y Y Y
Pf-Get-Top-List-Box-Item Y Y Y
Pf-Get-Typeface-Availability * Y *
Pf-Get-Typeface-Info * Y *
Pf-Get-Typeface-Names Y Y Y
Pf-Get-Version-Number Y Y Y
Pf-Get-Window-Data Y Y Y
Pf-Get-Window-Frame-Handle * Y x
Pf-Get-Window-Info Y Y Y
Pf-Get-Window-System-Handle * Y *
Pf-Get-Window-Title Y Y Y
Pf-Hide-Mouse-Pointer * Y Y
Pf-Initialize Y Y Y
Pf-Insert-Block x Y Y
Pf-Insert-List-Box-Item Y Y Y
Pf-Insert-Sel-List-Item Y Y Y
Pf-Invoke-Message-Box Y Y *
Pf-Load-Bitmap x Y Y
Pf-Make-List-Box-Item-Visible Y Y Y
Pf-Map-Coordinate-Space Y Y Y
Pf-Map-Coordinates Y Y Y
Pf-Move-Bitmap Y Y Y
Pf-Move-Icon Y Y Y
Pf-Move-Window Y Y Y
Pf-Name-To-RGB x Y Y
Pf-Paste-From-Clipboard x Y Y
Pf-Peek-Event x x Y
Pf-Position-Cursor Y Y Y
Pf-Post-Event Y Y Y
Pf-Post-Queue-Event Y Y Y
Pf-Process-Side-File Y Y Y
Pf-Query-Bitmap-Size Y Y Y
Pf-Query-Button-Size Y Y Y
Pf-Query-Colormap x Y Y
Pf-Query-Default-Button x Y Y
Pf-Query-Entry-Field-Size Y Y Y
Pf-Query-Font * Y Y
Pf-Query-Label-Extent Y Y Y
Pf-Query-List-Box-Size Y Y Y
Pf-Query-Menu-Details x * x
Pf-Query-Next-Selected-Button Y Y Y
Pf-Query-Scroll-Bar-Size Y Y Y
Pf-Query-Sel-Box-Size Y Y *
Pf-Query-Text-Extent Y Y Y
Pf-Query-Working-Font Y Y Y
Pf-Read-Panel Y Y Y
Pf-Redraw-Windows Y Y Y
Pf-Remove-Emphasis Y Y Y
Pf-Replace-Bitmap x Y Y
Pf-Restore-Window-Arrangement Y Y Y
Pf-Retrieve-Block x Y Y
Pf-Rubber-Banded-Area Y Y Y
Pf-Rubber-Banded-Object Y Y Y
Pf-Save-Window-Arrangement Y Y Y
Pf-Scroll-Panel Y Y Y
Pf-Set-Ancestor Y Y *
Pf-Set-Attributes x Y Y
Pf-Set-Button-Details Y Y Y
Pf-Set-Button-State Y Y Y
Pf-Set-Color x Y Y
Pf-Set-Cursor-Style * Y *
Pf-Set-Dialog-Focus-Gadget Y Y Y
Pf-Set-Emphasis Y Y Y
Pf-Set-Entry-Field-Details Y Y *
Pf-Set-Entry-Field-Limit Y Y Y
Pf-Set-Entry-Field-Text Y Y Y
Pf-Set-Font * * *
Pf-Set-Group-Box-Details Y Y Y
Pf-Set-Input-Focus Y Y Y
Pf-Set-Label-Text Y Y Y
Pf-Set-List-Box-Details Y Y Y
Pf-Set-List-Box-Item-State Y Y Y
Pf-Set-List-Box-Item-Text Y Y Y
Pf-Set-Menu-Item-Property Y * *
Pf-Set-Menu-Item-Text Y Y Y
Pf-Set-Mouse-Position Y Y Y
Pf-Set-Mouse-Shape * Y *
Pf-Set-Object-Color x Y *
Pf-Set-Password-Character x x Y
Pf-Set-Scroll-Bar-Details Y Y *
Pf-Set-Scroll-Bar-Range * Y *
Pf-Set-Scroll-Step x Y Y
Pf-Set-Sel-Box-Details Y Y *
Pf-Set-Sel-Box-Limit x Y Y
Pf-Set-Sel-Box-Text Y Y Y
Pf-Set-Sel-List-Item-Text Y Y Y
Pf-Set-Slider-Position Y Y *
Pf-Set-System-Scroll-Bar-State x Y Y
Pf-Set-Window-Backdrop Y Y Y
Pf-Set-Window-Data Y Y Y
Pf-Set-Window-Size Y Y Y
Pf-Set-Window-Title Y Y Y
Pf-Set-Working-Font Y Y Y
Pf-Shift-Window Y Y Y
Pf-Show-Cursor Y Y Y
Pf-Show-Dialog-Box Y Y Y
Pf-Show-Help-Panel x Y x
Pf-Show-Help-Index x Y x
Pf-Show-Menu Y Y Y
Pf-Show-Mouse-Pointer * Y Y
Pf-Show-Object x Y Y
Pf-Show-Window Y Y Y
Pf-Show-Window-No-Focus Y Y Y
Pf-Shrink-Wrap-Window Y Y Y
Pf-Sound-Bell * Y *
Pf-Subclass-Object x Y Y
Pf-Subclass-Scrollbars x x Y
Pf-Terminate Y Y Y
Pf-Translate-Mouse-Coordinates Y Y Y
Pf-Try-Text-Fit Y Y Y
Pf-Unload-Bitmap x Y Y
Pf-Unshow-Cursor Y Y Y
Pf-Unshow-Dialog-Box Y Y Y
Pf-Unshow-Window Y Y Y
Pf-Update-Progress x Y Y
Pf-Write-Clipboard Y Y Y
Pf-Write-Panel Y Y Y

Copyright © 1999 MERANT International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.

PreviousUsing GUIs from Third Party Tools Using Panels Version 2Next"