home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
vxcliser.zip
/
VXREXX.3
/
SHARED
/
OBJECT.VRS
Wrap
Text File
|
1994-12-23
|
27KB
|
809 lines
/*:VRX Object
*/
Object: procedure expose Globals.
return
/*
Object.VRS
This file contains subroutines to help manage CUA '91 style views of objects.
There are two types of views to be considered, list views and individual views.
The list views are implemented by containers; the individual views by windows.
The routines in this file help to track the relationship between the views of
an object. In particular, they ensure that objects in list views are marked
as in-use when the objects have individual views open, and that when a view is
already open an attempt to open it again displays the existing view rather
than opens a new view.
Individual views are opened from list views, but in general the list views
can be closed without closing the individual views. As a result, when a list
view is opened the some of the records in the view may need to be marked
as in-use. Similarly, if the delta scroll feature of containers is used
records representing objects can scroll out of and back into a container
and must have their emphasis set dynamically. More than one list view can
be open at a time (for example, a detail view and an icon view) so when an
individual view is opened or closed records in more than one container may
need to have their emphasis changed.
In this implementation, objects are assumed to belong to groups and
to be identified by key values with in the group. For example, the group
might correspond to a table in a database and the key values to the
primary key for the table. It is assumed that a container displays information
from only one group. The key for a record is either the record handle
or the values of fields within the container. A record handle can only be
used in simple cases where the records in the container will not be
destroyed while a view is open, and only one list view can be opened.
- External routines:
ObjectListOpened: A list view has been opened.
ObjectListClosed: A list view has been closed.
ObjectListChanged: Records in a list view have changed.
ObjectListFindRecord: Return the record that matches a specific
object.
ObjectOpen: Open an individual view.
ObjectClosed: An individual view has been closed.
ObjectCloseAll: Post close events to all individual views.
ObjectGetKeys: Return the key value corresponding to an
individual view.
ObjectRefresh: Post refresh events to all views of an object.
- Internal routines
Internal routines start with a double underscore and are not meant to be called
directly. They generally assume the arguments have already been checked and are
in the correct format.
- Global variables
- The code assumes that the global variables are initialized to 0 or to a non-numeric
value.
- List of list views:
Globals.!__Objects.!Groups.0 Count.
Globals.!__Objects.!Groups.i.!Group Group name.
Globals.!__Objects.!Groups.i.!Container The internal name of the container.
Globals.!__Objects.!Groups.i.!KeyFields.0 Count.
Globals.!__Objects.!Groups.i.!KeyFields.j The jth key field for this object.
Note: A group name may appear more than once in the list, corresponding
to multiple list views.
- List of open windows:
Globals.!__Objects.!Windows.0 Count.
Globals.!__Objects.!Windows.i.!Group Group name ==> list views.
Globals.!__Objects.!Windows.i.!Keys.0 Count.
Globals.!__Objects.!Windows.i.!Keys.j The value of the jth key for this object.
Globals.!__Objects.!Windows.i.!WindowName The external name of the window.
Globals.!__Objects.!Windows.i.!Window Internal name of the window.
Note: Assume only ever one window of each type open per object, so the
!Window is a unique key as well as !Group + !Keys + !WindowName.
*/
/*****************************************************************************
num = __ObjectCount( count )
count Possibly uninitialized count value.
num Count or 0
*****************************************************************************/
__ObjectCount: procedure
parse arg count
if DataType( count ) \= "NUM" then do
count = 0
end
return count
/*****************************************************************************
keyFields.0 = <count>
keyFields.i = <ith key field>
ok = ObjectListOpened( group, container )
group The name of the group displayed in the list view (not case sensitive)
container The name of the container.
keyFields. A REXX array holding the key fields.
ok 1 if OK; 0 if not.
- Set keyFields.0 to 0 to use the container's record handles as keys.
- The keyFields.1 must be string type as this is assumed when searching the
container
- Use the same group name for all containers which are displaying
common objects. All containers in a group must use the same
keyFields.
- Either ObjectListOpened after the container has been populated so
emphasis can be set on the records, or call ObjectListChanged after
adding the records.
*****************************************************************************/
ObjectListOpened: procedure expose Globals. keyFields.
/*
say "ObjectListOpened"
trace r
*/
parse arg group, container
/* Return value */
ok = 0
/* Check arguments */
group = translate( group )
if VRIsValidObject( container ) = 0 then signal ObjectListOpenedDone
container = VRGet( container, "Self" )
if DataType( keyFields.0 ) \= "NUM" then signal ObjectListOpenedDone
/* Record info */
count = __ObjectCount( Globals.!__Objects.!Groups.0 )
count = count + 1
Globals.!__Objects.!Groups.0 = count
Globals.!__Objects.!Groups.count.!Group = group
Globals.!__Objects.!Groups.count.!Container = container
do j = 0 to keyFields.0
Globals.!__Objects.!Groups.count.!KeyFields.j = keyFields.j
end
call ObjectListChanged container
ok = 1
ObjectListOpenedDone:
return ok
/*****************************************************************************
index = __ObjectFindGroup( container )
container The internal name of the container.
index The index of the container in the group list, or 0.
*****************************************************************************/
__ObjectFindGroup: procedure expose Globals.
parse arg container
count = Globals.!__Objects.!Groups.0
index = 0
do i = 1 to count
if Globals.!__Objects.!Groups.i.!Container = container then do
index = i
leave
end
end
return index
/*****************************************************************************
ok = ObjectListClosed( container )
container The name of the container.
ok 1 if OK; 0 if not.
- If the container no longer exists the name passed must be the internal
name.
*****************************************************************************/
ObjectListClosed: procedure expose Globals.
/*
say "ObjectListClosed"
trace r
*/
parse arg container
/* Return value */
ok = 0
/* Check argument */
if VRIsValidObject( container ) then do
container = VRGet( container, "Self" )
end
/* Unrecord info */
index = __ObjectFindGroup( container )
if index = 0 then signal ObjectListClosedDone
count = Globals.!__Objects.!Groups.0
Globals.!__Objects.!Groups.0 = count - 1
do i = index to count - 1
j = i + 1
Globals.!__Objects.!Groups.i.!Group = Globals.!__Objects.!Groups.j.!Group
Globals.!__Objects.!Groups.i.!Container = Globals.!__Objects.!Groups.j.!Container
keyCount = Globals.!__Objects.!Groups.j.!KeyFields.0
do k = 0 to keyCount
Globals.!__Objects.!Groups.i.!KeyFields.k = Globals.!__Objects.!Groups.j.!KeyFields.k
end
end
drop Globals.!__Objects.!Groups.count.!Group
drop Globals.!__Objects.!Groups.count.!Container
keyCount = Globals.!__Objects.!Groups.count.!KeyFields.0
do k = 0 to keyCount
drop Globals.!__Objects.!Groups.count.!KeyFields.k
end
ok = 1
ObjectListClosedDone:
return ok
/*****************************************************************************
call __ObjectListGetKeys groupIndex, record
groupIndex The index of the container.
record The current record.
keys. A REXX array holding the keys for the current record.
*****************************************************************************/
__ObjectListGetKeys: procedure expose Globals. keys.
parse arg groupIndex, record
/* Return value */
keys.0 = 1
keys.1 = record
/* Fetch keys */
container = Globals.!__Objects.!Groups.groupIndex.!Container
keyCount = Globals.!__Objects.!Groups.groupIndex.!KeyFields.0
if keyCount = 0 then signal __ObjectListGetKeysDone
do i = 1 to keyCount
keyCol = Globals.!__Objects.!Groups.groupIndex.!KeyFields.i
keys.i = VRMethod( container, "GetFieldData", record, keyCol )
end
keys.0 = keyCount
__ObjectListGetKeysDone:
return
/*****************************************************************************
keys.0 = count
keys.i = ith key
record = __ObjectFindRecord( groupIndex )
groupIndex The index of the container.
targetKeys. The object to match.
record The matching record or ""
*****************************************************************************/
__ObjectFindRecord: procedure expose Globals. targetKeys.
parse arg groupIndex
/* Return value */
record = ""
/* Search for record with matching keys
NOTE: The first key must be a string type for that is all
the container FindRecord method handles.
*/
container = Globals.!__Objects.!Groups.groupIndex.!Container
keyCount = Globals.!__Objects.!Groups.groupIndex.!KeyFields.0
target = targetKeys.1
if keyCount = 0 then do
if VRMethod( container, "ValidateRecord", target ) then do
record = target
end
signal __ObjectFindRecordDone
end
record = "First"
do forever
record = VRMethod( container, "FindRecord", target, "Detail", record, "Case" )
if record = "" then signal __ObjectFindRecordDone
call __ObjectListGetKeys groupIndex, record
match = 1
do j = 0 to targetKeys.0
if keys.j \= targetKeys.j then do
match = 0
leave
end
end
if match = 1 then leave
end
__ObjectFindRecordDone:
return record
/*****************************************************************************
ok = __ObjectSetInUse( groupIndex, windowIndex, onOff )
groupIndex Index of the container
windowIndex Index of the window
onOff 1 for on; 0 for off.
ok 1 for ok; 0 for not ok.
*****************************************************************************/
__ObjectSetInUse: procedure expose Globals.
parse arg groupIndex, windowIndex, onOff
keyCount = Globals.!__Objects.!Windows.windowIndex.!Keys.0
do i = 0 to keyCount
targetKeys.i = Globals.!__Objects.!Windows.windowIndex.!Keys.i
end
targetKeys.0 = keyCount
record = __ObjectFindRecord( groupIndex )
if record = "" then signal __ObjectSetInUseDone
container = Globals.!__Objects.!Groups.groupIndex.!Container
call VRMethod container, "SetRecordAttr", record, "InUse", onOff
__ObjectSetInUseDone:
return record
/*****************************************************************************
ok = ObjectListChanged( container )
container The name of the container.
ok 1 if OK; 0 if not.
- Call after adding records to a container to have their
emphasis set.
*****************************************************************************/
ObjectListChanged: procedure expose Globals.
/*
say "ObjectListChanged"
trace r
*/
parse arg container
/* Return value */
ok = 0
/* Check arguments */
if VRIsValidObject( container ) = 0 then signal ObjectListChangedDone
container = VRGet( container, "Self" )
/* Update hatching */
index = __ObjectFindGroup( container )
if index = 0 then signal ObjectListChangedDone
group = Globals.!__Objects.!Groups.index.!Group
count = __ObjectCount( Globals.!__Objects.!Windows.0 )
do i = 1 to count
if Globals.!__Objects.!Windows.i.!Group = group then do
call __ObjectSetInUse index, i, 1
end
end
ObjectListChangedDone:
return ok
/*****************************************************************************
keys.0 = count
keys.i = ith key value
record = ObjectListFindRecord( container )
container The name of the container.
keys The key value for the object to find
*****************************************************************************/
ObjectListFindRecord: procedure expose Globals. keys.
/*
say "ObjectListFindRecord"
trace r
*/
parse arg container
/* Return value */
record = ""
/* Check arguments */
if VRIsValidObject( container ) = 0 then signal ObjectListFindRecordDone
container = VRGet( container, "Self" )
/* Find the group */
index = __ObjectFindGroup( container )
if index = 0 then signal ObjectListFindRecordDone
/* Find the record */
keyCount = keys.0
do i = 0 to keyCount
targetKeys.i = keys.i
end
record = __ObjectFindRecord( index )
ObjectListFindRecordDone:
return record
/*****************************************************************************
index = __ObjectFindWindow( group, windowName, start )
group The object's group
windowName The name of the window (upper case), or ""
start The start index
keys. The list of key values.
index The index of the window or 0.
*****************************************************************************/
__ObjectFindWindow: procedure expose Globals. keys.
parse arg group, windowName, start
index = 0
count = __ObjectCount( Globals.!__Objects.!Windows.0 )
if count = 0 then signal __ObjectFindWindowDone
do i = start to count
if Globals.!__Objects.!Windows.i.!Group \= group then iterate i
do j = 1 to keys.0
if Globals.!__Objects.!Windows.i.!Keys.j \= keys.j then iterate i
end
if windowName \= "" then do
if Globals.!__Objects.!Windows.i.!WindowName \= WindowName then iterate i
end
/* Found match */
index = i
leave
end
__ObjectFindWindowDone:
return index
/*****************************************************************************
index = __ObjectFindWindowFromHandle( window )
window The name of the window (upper case)
index The index of the window or 0.
*****************************************************************************/
__ObjectFindWindowFromHandle: procedure expose Globals.
parse arg window
index = 0
count = Globals.!__Objects.!Windows.0
if count = 0 then signal __ObjectFindWindowFromHandleDone
do i = 1 to count
if Globals.!__Objects.!Windows.i.!Window \= window then iterate i
/* Found match */
index = i
leave
end
__ObjectFindWindowFromHandleDone:
return index
/*****************************************************************************
window = ObjectOpen( container, record, windowName )
container The name of the container holding "record".
record The handle of the record representing the object.
windowName The external name of the secondary window to open.
window The internal name of the window opened.
- ObjectOpen opens a window to view the object associated with the specified
record.
- Reopening an open view activates the currently open window rather then
creating a new one.
- You must call ObjectClosed when the window is closed so the list
of windows open for the object can be updated.
*****************************************************************************/
ObjectOpen: procedure expose Globals.
/*
say "ObjectOpen"
trace r
*/
parse arg container, record, windowName
/* Return value */
window = ""
/* Check arguments */
if VRIsValidObject( container ) = 0 then signal ObjectOpenDone
container = VRGet( container, "Self" )
groupIndex = __ObjectFindGroup( container )
if groupIndex = 0 then signal ObjectOpenDone
group = Globals.!__Objects.!Groups.groupIndex.!Group
if VRMethod( container, "ValidateRecord", record ) = 0 then signal ObjectOpenDone
windowName = translate( windowName )
call __ObjectListGetKeys groupIndex, record
/* If the view is already open on the object just activate it */
i = __ObjectFindWindow( group, windowName, 1 )
if i \= 0 then do
window = Globals.!__Objects.!Windows.i.!window
windowState = VRGet( window, "WindowState" )
if windowState = "Minimized" then do
call VRSet window, "WindowState", "Normal"
end
call VRSet window, "Visible", 1
call VRMethod window, "Activate"
signal ObjectOpenDone
end
/* The view is not open so open and record it. */
window = VRLoadSecondary( windowName )
if window = "" then signal ObjectOpenDone
count = __ObjectCount( Globals.!__Objects.!Windows.0 )
count = count + 1
Globals.!__Objects.!Windows.0 = count
Globals.!__Objects.!Windows.count.!Group = group
do j = 0 to keys.0
Globals.!__Objects.!Windows.count.!Keys.j = keys.j
end
Globals.!__Objects.!Windows.count.!WindowName = windowName
Globals.!__Objects.!Windows.count.!Window = window
/* Hatch icons */
windowIndex = count
count = __ObjectCount( Globals.!__Objects.!Groups.0 )
do i = 1 to count
if Globals.!__Objects.!Groups.i.!Group = group then do
call __ObjectSetInUse i, windowIndex, 1
end
end
ObjectOpenDone:
return window
/*****************************************************************************
ok = ObjectClosed( window )
window The internal name of the window that was closed.
ok 1 if OK; 0 if not.
- Update the object open window list and the corresponding container record's
state.
*****************************************************************************/
ObjectClosed: procedure expose Globals.
/*
say "ObjectClosed"
trace r
*/
parse arg window
/* Return value */
closed = 0
/* Check arguments */
index = __ObjectFindWindowFromHandle( window )
if index = 0 then signal ObjectClosedDone
/* Unhatch icons if no other view open */
group = Globals.!__Objects.!Windows.index.!Group
keyCount = Globals.!__Objects.!Windows.index.!Keys.0
do k = 0 to keyCount
keys.k = Globals.!__Objects.!Windows.index.!Keys.k
end
otherIndex = 0
do forever
otherIndex = __ObjectFindWindow( group, "", otherIndex+1 )
if otherIndex = 0 then leave /* No other window */
if otherIndex \= index then leave /* Found a different window */
end
if otherIndex = 0 then do
count = Globals.!__Objects.!Groups.0
do i = 1 to count
if Globals.!__Objects.!Groups.i.!Group = group then do
call __ObjectSetInUse i, index, 0
end
end
end
/* Unrecord window */
count = Globals.!__Objects.!Windows.0
Globals.!__Objects.!Windows.0 = count - 1
do i = index to count - 1
j = i + 1
Globals.!__Objects.!Windows.i.!Group = Globals.!__Objects.!Windows.j.!Group
keyCount = Globals.!__Objects.!Windows.j.!Keys.0
do k = 0 to keyCount
Globals.!__Objects.!Windows.i.!Keys.k = Globals.!__Objects.!Windows.j.!Keys.k
end
Globals.!__Objects.!Windows.i.!WindowName = Globals.!__Objects.!Windows.j.!WindowName
Globals.!__Objects.!Windows.i.!Window = Globals.!__Objects.!Windows.j.!Window
end
drop Globals.!__Objects.!Windows.count.!Group
keyCount = Globals.!__Objects.!Windows.count.!Keys.0
do k = 0 to keyCount
drop Globals.!__Objects.!Windows.count.!Keys.k
end
drop Globals.!__Objects.!Windows.count.!WindowName
drop Globals.!__Objects.!Windows.count.!Window
closed = 1
ObjectClosedDone:
return closed
/*****************************************************************************
ok = ObjectCloseAll( container, record )
container The name of the container.
record The handle of the record corresponding to the object.
ok 1 if OK; 0 if not.
- Close all the opened windows of an object.
*****************************************************************************/
ObjectCloseAll: procedure expose Globals.
/*
say "ObjectCloseAll"
trace r
*/
parse arg container, record
/* Return value */
closed = 0
/* Check arguments, set container & keys */
if VRIsValidObject( container ) = 0 then signal ObjectCloseAllDone
container = VRGet( container, "Self" )
groupIndex = __ObjectFindGroup( container )
group = Globals.__Objects.!Groups.groupIndex.!Group
if VRMethod( container, "ValidateRecord", record ) = 0 then signal ObjectCloseAllDone
call __ObjectListGetKeys groupIndex, record
/* Post close events to all matching windows */
count = __ObjectCount( Globals.!__Objects.!Windows.0 )
do i = 1 to count
if Globals.!__Objects.!Windows.i.!Group \= group then iterate i
do j = 0 to keys.0
if Globals.!__Objects.!Windows.i.!Keys.j \= keys.j then iterate i
end
/* Found match */
window = Globals.!__Objects.!Windows.i.!Window
call VRMethod window, "PostEvent", "Close"
end
closed = 1
ObjectCloseAllDone:
return closed
/*****************************************************************************
call ObjectGetKeys window
window The internal name of the individual view window.
keys. The key values for that window.
*****************************************************************************/
ObjectGetKeys: procedure expose Globals. keys.
/*
say "ObjectGetKeys"
trace r
*/
parse arg window
/* Return value */
keys.0 = 0
/* Check arguments */
index = __ObjectFindWindowFromHandle( window )
if index = 0 then signal ObjectGetKeysDone
keyCount = Globals.!__Objects.!Windows.index.!Keys.0
do k = 0 to keyCount
keys.k = Globals.!__Objects.!Windows.index.!Keys.k
end
ObjectGetKeysDone:
return
/*****************************************************************************
keys.0 = count
keys.i = ith key
call ObjectRefresh group, type
keys. An object identifier.
group The group to refresh
type The type of refresh to perform, passed as event info.
ok 1 if OK; 0 it not.
- Generates a "Refresh" event to all list views and all matching individual
views.
- The following VRInfo is available:
Object The internal name of the object receiving the post
Window The internal name of the object's parent window
Event "Refresh"
Type The value of the type parameter.
- The refresh routines are called via a post rather than a call
so that the current object will be set correctly in case
multiple instances of the object are loaded.
*****************************************************************************/
ObjectRefresh: procedure expose Globals. keys.
/*
Say "ObjectRefresh"
trace r
*/
parse arg group, type
group = translate( group )
/* Post to all containers */
count = __ObjectCount( Globals.!__Objects.!Groups.0 )
do i = 1 to count
if Globals.!__Objects.!Groups.i.!Group \= group then iterate i
/* Found match */
container = Globals.!__Objects.!Groups.i.!Container
containerName = VRGet( container, "Name" )
eventString = "Call " || containerName || "_Refresh"
call VRMethod "Application", "PostQueue", 0, 1, eventString,,
"Object", container,,
"Event", "Refresh",,
"Type", type
end
/* Post to all matching windows */
count = __ObjectCount( Globals.!__Objects.!Windows.0 )
do i = 1 to count
if Globals.!__Objects.!Windows.i.!Group \= group then iterate i
do j = 1 to keys.0
if Globals.!__Objects.!Windows.i.!Keys.j \= keys.j then iterate i
end
/* Found match */
window = Globals.!__Objects.!Windows.i.!window
windowName = Globals.!__Objects.!Windows.i.!WindowName
eventString = "Call " || windowName || "_Refresh"
call VRMethod "Application", "PostQueue", 0, 1, eventString,,
"Object", container,,
"Event", "Refresh",,
"Type", type
end
return