Module dep_item.pkg

     1//*** DEP_ITEM.PKG
     2//*** Dependent Item support package
     3//*** 1994-Mar-1  LS
     4
     5//*** 06/01/94  -JJT
     6//*** Set Auto_dependent_item_state to default to false (setting this
     7//*** true creates too great of an overhead.
     8
     9//*** 1994-Mar-22  LS
    10//*** got this updated version from john. he moved some code into mixins
    11//*** for deos and views.
    12//*** I added prototype object stuff from john and converted it to use
    13//*** "manual" delegation and broadcasting. Also added "non-deo" mixin
    14//*** for dep-item support in entry_client and text_window classes.
    15
    16//*** 1994-Mar-1  LS
    17//*** first attempt
    18
    19// 02/17/95 JJT - Removed checking for component_state before delegating.
    20//                Component_state is not set yet. End_construct_Object
    21//                does this. Has_components should be ok. **JJT**(2)
    22//                This means that you should not use REGISTER_DEPENDENT_
    23//                ITEMS without an entry_view_client0. Such is life.
    24//************************************************************************
    25
    26//*** Notes:
    27//*** Contains mixin classes for view and DEO classes to automatically
    28//*** define item_groups for same file.field within same view.
    29//*** Allows use of Dependent_Entry_Item command. Only supported within
    30//*** DEOs nested within Views. Dependent_Entry_Item MUST use a file.field
    31//*** for its data. All dependent matching file.fields within a view are
    32//*** grouped together. If only one item appears in a group, the item group
    33//*** is not created.
    34
    35//*** Dependent_entry_item command for forcing item into item group.
    36//*** For efficiency, turn off auto_dependent_item_state, and use this,
    37//*** or send register_dependent_item right after the entry_item.
    38
    39#COMMAND DEPENDENT_ENTRY_ITEM
    40    #CHECK !1 _CVWLR#GU // must be a file.field
    41    ENTRY_ITEM !1 !2 !3 !4 !5 !6 !7 !8 !9
    42    SEND REGISTER_DEPENDENT_ITEM
    43#ENDCOMMAND
    44
    45#COMMAND SIZED_ITEM_GROUP R . // item_group command with size passed as parm.
    46  #PUSH !Zd
    47  #PUSH !Ze
    48  #SET ZD$ 0
    49  !A [] $462 !1        //create new item group; size is passed as arg
    50  #SET ZE$ !a
    51#ENDCOMMAND
    52
    53use set.pkg
    54
    55//*** Class for set of item groups
    56
    57// This class defines a set of ID strings. It has a child array
    58// (item_group_ids) that stores object ids of arrays that contain the
    59// item group information for each ID. Each of the item group arrays
    60// contains a list of dependent object ids and item numbers.
    61
    62{ Visibility=Private ClassLibrary=Windows }
    63class item_group_set is a set
    64    procedure Construct_Object
    65        forward send construct_object
    66
    67        object item_group_ids is an array
    68        end_object
    69    end_procedure
    70
    71    procedure add_group_item integer deo_obj integer deo_itm string group_id
    72        integer total_groups count group_index group_obj
    73        integer deo_index
    74
    75        // find or create object for this group
    76        get find_element group_id to group_index
    77
    78        if group_index ne -1 get integer_value of ;
    79                (item_group_ids(Self)) item group_index to group_obj
    80        else begin
    81            send add_element group_id
    82            get find_element group_id to group_index
    83                    // it'd be nice if add_element returned this!
    84
    85            object item$group is an array
    86                move self to group_obj
    87            end_object
    88
    89            set array_value of (item_group_ids(Self)) ;
    90                    item group_index to group_obj
    91        end
    92
    93        // add deo item info to group object
    94        get item_count of group_obj to deo_index
    95        set array_value of group_obj item deo_index to deo_obj
    96        set array_value of group_obj item (deo_index+1) to deo_itm
    97    end_procedure
    98
    99    procedure create_item_groups
   100        integer count total_groups group_obj total_deos deo_index
   101        integer deo_offset igs_obj
   102
   103        get item_count to total_groups
   104
   105        if total_groups le 0 procedure_return
   106
   107        decrement total_groups
   108        move (item_group_ids(Self)) to igs_obj
   109
   110        for count from 0 to total_groups
   111            get integer_value of igs_obj item count to group_obj
   112            get item_count of group_obj to total_deos
   113            move (total_deos / 2) to total_deos
   114
   115            if total_deos gt 1 begin // only make item group if necessary
   116                sized_item_group (total_deos)
   117                    decrement total_deos
   118
   119                    for deo_index from 0 to total_deos
   120                        move (deo_index * 2) to deo_offset
   121                        dependent_item (integer_value(group_obj,deo_offset)) ;
   122                                (integer_value(group_obj,deo_offset+1))
   123                    loop
   124                end_item_group
   125            end
   126        loop
   127    end_procedure
   128end_class
   129
   130//*** for the entry_view_client class
   131class View_Dependent_item_mixin is a mixin
   132
   133    { Visibility=Private }
   134    procedure Define_View_Dependent_item
   135        { Visibility=Private }
   136        property integer deo_item_groups 0
   137
   138        { DesignTime=False }
   139        { PropertyType=Boolean }
   140        property Integer Auto_Dependent_Item_State False
   141    end_procedure
   142
   143    { Visibility=Private }
   144    procedure add_group_item integer deo_obj integer deo_itm string group_id
   145        integer di_groups
   146
   147        get deo_item_groups to di_groups
   148
   149        if di_groups eq 0 begin
   150            object deo$item$groups is an item_group_set
   151                move Self to di_groups
   152            end_object
   153
   154            set deo_item_groups to di_groups
   155        end
   156
   157        send add_group_item to di_groups deo_obj deo_itm group_id
   158    end_procedure
   159
   160    { Visibility=Private }
   161    procedure register_all_deo_items integer obj
   162        if (has_components_state(Self)) ;
   163                broadcast send register_all_deo_items obj
   164    end_procedure
   165
   166    { Visibility=Private }
   167    procedure Construct_Item_Groups
   168        integer obj
   169
   170        move self to obj
   171
   172        If (Auto_Dependent_Item_State(Self)) ;
   173                Send Register_all_deo_items obj
   174
   175        move (deo_item_groups(Self)) to obj
   176
   177        If Obj gt 0 Begin
   178            send create_item_groups to obj
   179            send destroy of obj
   180        End
   181
   182    end_procedure
   183end_class
   184
   185//*** for DEO entry_item-oriented classes
   186
   187class DEO_Dependent_item_mixin is a mixin
   188    // send this to register one dependent item based on its file and field
   189    // (used by dependent_entry_item command)
   190
   191    { Visibility=Private }
   192    procedure register_dependent_item integer itm
   193        integer curitm fil fld pobj
   194
   195        get prototype_object to pobj
   196
   197        if num_arguments gt 0 move itm to curitm
   198        else get current_item of pobj to curitm
   199
   200        get data_file of pobj item curitm to fil
   201
   202        if fil ne 0 get data_field of pobj item curitm to fld
   203
   204        Send Register_Deo_Item curitm (string(fil) + "," + string(fld))
   205    end_procedure
   206
   207    // send this to register one deo item based on a specified group_id
   208    // (group id can be any unique string; this allows you to make non-dbms
   209    // dependent items; [we use "##,##" for file.field])
   210
   211    { Visibility=Private }
   212    procedure register_deo_item integer itm string group_id integer view_obj
   213        integer curobj curitm
   214
   215        if group_id eq "" procedure_return // do nothing if no group_id
   216
   217        move Self to curobj
   218
   219        if num_arguments ge 3 ;
   220                send add_group_item to view_obj curobj itm group_id
   221        else send add_group_item curobj itm group_id
   222    end_procedure
   223
   224    { Visibility=Private }
   225    procedure register_all_deo_items integer view_obj
   226        integer itm_cnt itm_idx fil fld pobj
   227
   228        get prototype_object to pobj
   229
   230        Get Item_Count of pobj to itm_cnt
   231        Decrement itm_cnt
   232
   233        for itm_idx from 0 to itm_cnt
   234            get data_file of pobj item itm_idx to fil
   235
   236            if fil ne 0 begin
   237                get data_field of pobj item itm_idx to fld
   238                if num_arguments ge 1 Send Register_Deo_Item itm_idx ;
   239                        (string(fil) + "," + string(fld)) view_obj
   240                else Send Register_Deo_Item itm_idx ;
   241                        (string(fil) + "," + string(fld))
   242            end
   243            Else if num_arguments ge 1 ;
   244                    Send Register_Deo_Item itm_idx "" view_obj
   245            else Send Register_Deo_Item itm_idx ""
   246                // call it for non-dbms entry_items passing "" as
   247                // group_id so user can override
   248        Loop
   249
   250        if (has_components_state(Self)) ;
   251                broadcast send register_all_deo_items view_obj
   252    End_procedure
   253
   254    { Visibility=Private }
   255    procedure add_group_item integer deo_obj integer deo_itm string group_id
   256        // **JJT** - Component_state not yet defined
   257        // if (component_state(self)) ;
   258        delegate send add_group_item deo_obj deo_itm group_id
   259    end_procedure
   260end_class
   261
   262//*** for classes that must pass dep-item messages on to parents/children.
   263class Non_Dependent_item_mixin is a mixin
   264    { Visibility=Private }
   265    procedure register_all_deo_items integer view_obj
   266        if (has_components_state(Self)) ;
   267                broadcast send register_all_deo_items view_obj
   268    End_procedure
   269
   270    { Visibility=Private }
   271    procedure add_group_item integer deo_obj integer deo_itm string group_id
   272        // **JJT** - Component_state not yet defined
   273        //if (component_state(self)) ;
   274                delegate send add_group_item deo_obj deo_itm group_id
   275    end_procedure
   276End_Class
   277