Module cDbCJGrid.pkg

     1Use Windows.pkg
     2Use cCJGrid.pkg
     3Use cCJDeoMenuItemClasses.pkg
     4Use refmodes.pkg
     5
     6// define Grid request Find modes
     7Enum_List
     8    Define rfmFindAll 
     9    Define rfmFindMainOnly
    10    Define rfmFindMainSuper
    11    Define rfmFindNone 
    12    Define rfmFindParentOnly
    13End_Enum_List
    14
    15#IFNDEF ddrtsNone
    16Enum_List
    17    Define ddrtsNone
    18    Define ddrtsFound
    19    Define ddrtsCleared
    20End_Enum_List
    21#ENDIF
    22
    23Use cdbCJGridColumn.pkg
    24Use cDbCJGridDataSource.pkg
    25Use Server.pkg
    26Use verify.pkg
    27
    28{ DataAware=True }
    29{ CompositeClass=cDbCJGridColumn }
    30{ HelpTopic=cDbCJGrid }
    31Class cDbCJGrid is a cCJGrid
    32
    33    Procedure Construct_Object
    34        Forward Send Construct_Object
    35        
    36        { Category=Behavior } 
    37        Property Integer Ordering -1 // initial ordering
    38        { DesignTime=False } 
    39        Property Boolean pbPromptListBehavior False // determines behavior of various grid vs prompt list
    40        { Category=Behavior } 
    41        { EnumList="rfmFindAll, rfmFindMainOnly, rfmFindMainSuper, rfmFindNone, rfmFindParentOnly" }
    42        Property Integer peRequestFindMode rfmFindAll // determines how request_find behaves        
    43        
    44        { Visibility=Private } 
    45        Property Boolean entry_refresh_State False // required by dds
    46        
    47        { Visibility=Private } 
    48        Property Boolean pbUnOrdered False // tracks if new records might have made the list out of order
    49        
    50        { Category=Behavior } 
    51        Property Boolean pbAutoRegenerate True // if false it will never try to reorder your additions
    52        
    53        { Category=Behavior } 
    54        Property Boolean pbStaticData False // if true, load all data at once and it is static
    55       
    56        
    57        
    58        On_Key kFind_Previous       Send Find_Previous
    59        On_Key kFind                Send Find_GE
    60        On_Key kFind_Next           Send Find_Next
    61        On_Key kClear_All           Send Request_Clear_All
    62        
    63        Send define_server
    64        Send define_verify
    65        // from nesting.pkg
    66        { Visibility=Private }
    67        Property Integer Component_State        0
    68        { Visibility=Private }
    69        Property Integer Has_Components_State   0
    70
    71
    72        Set  Auto_Fill_State to True  // note this only applies to constrained tables. We must define this
    73                                      // here because the runtime DD code uses this.
    74
    75        Set Verify_Delete_msg to (RefFunc(Line_Delete_Confirmation))
    76        Set Verify_Save_msg   to (RefFunc(No_Confirmation))
    77
    78    End_Procedure  // Construct_Object
    79
    80    // the server mixin logic is complicated and it is best to just use it as is
    81    Import_Class_Protocol server_mixin
    82    // this procedure **replaces** set Changed_state from the server mixin. We are not going to set
    83    // the watched server's (parent DDs) to changed_state. This is not needed and is heavy handed because
    84    // this sets all watched servers and not the single column that triggered the change. We probably don't
    85    // need to set watched servers in the grids. We are setting the main server's DD to changed and that is enough
    86    { NoDoc=True }
    87    Procedure Set Changed_State for cDbCJGrid Integer newVal
    88        Integer srvr# wsrvr
    89        If not (Change_Disabled_State(Self)) Begin
    90           // Forward Set Changed_State to newVal // change -- there is nowhere to forward this to
    91           Get server to srvr#
    92        
    93           // if deferred keep the server out of it.
    94           If not (deferred_State(Self)) Begin
    95              If (newVal and srvr#) Begin
    96                  Set Changed_State of srvr# to True
    97                  //    // **JJT**(4) - if no watcher do nothing // change -- don't set watched servers
    98                  //    Get Watched_Servers to wsrvr
    99                  //    If wsrvr Set Changed_State of wSrvr to True
   100              End
   101              // Remove is changed-state=false, not active and not static
   102              If ( not(newVal) and not(Active_State(Self)) and ;
   103                   not(Static_Server_State(Self)) ) ;
   104                       Send remove_DEO_from_Server
   105           End
   106        End
   107    End_Procedure
   108    
   109    
   110    
   111    Import_Class_Protocol verify_mixin
   112    
   113    Procedure Request_Cancel
   114        Delegate Send Request_Cancel
   115    End_Procedure
   116    
   117
   118    // called by constructor
   119    { NoDoc=True }
   120    Function CreateDataSource Returns Handle
   121        Handle hoDataSource
   122        Get Create (RefClass(cDbCJGridDataSource)) to hoDataSource
   123        Function_Return hoDataSource
   124    End_Procedure
   125
   126    // default context menu for db grids
   127    { NoDoc=True }
   128    Function CreateContextMenu Returns Handle
   129        Handle hoMenu hoMenu1
   130        Get Create (RefClass(cCJContextMenu)) to hoMenu
   131        Get Create of hoMenu (RefClass(cCJPromptMenuItem)) to hoMenu1
   132        Set pbControlBeginGroup of hoMenu1 to True
   133        Get Create of hoMenu (RefClass(cCJFindNextMenuItem)) to hoMenu1
   134        Set pbControlBeginGroup of hoMenu1 to True
   135        Get Create of hoMenu (RefClass(cCJFindPreviousMenuItem)) to hoMenu1
   136        Get Create of hoMenu (RefClass(cCJClearMenuItem)) to hoMenu1
   137        Set pbControlBeginGroup of hoMenu1 to True
   138        Get Create of hoMenu (RefClass(cCJClearAllMenuItem)) to hoMenu1
   139        Get Create of hoMenu (RefClass(cCJSaveMenuItem)) to hoMenu1
   140        Get Create of hoMenu (RefClass(cCJDeleteMenuItem)) to hoMenu1
   141        Function_Return hoMenu
   142    End_Function
   143    
   144    // use this to set any special properties in the datasource that might be
   145    // needed for this particular grid and data source. With db grids we need to
   146    // update the Server, Main_file and Ordering
   147    { NoDoc=True }
   148    Procedure BindDataSource
   149        Integer iOrder
   150        Boolean bDDReadMode bReverseOrdering bStatic
   151        Handle hoDD hoDataSource
   152        Get Server to hoDD
   153        Get Ordering to iOrder
   154        Get phoDataSource to hoDataSource
   155        Get Deferred_State to bDDReadMode
   156        Get pbReverseOrdering to bReverseOrdering
   157        Get pbStaticData to bStatic
   158        Set Server of hoDataSource to hoDD
   159        // actual ordering may be determined by the Server. If not, here is our suggestion
   160        Set piGridOrdering of hoDataSource to iOrder
   161        Set pbReverseOrdering of hoDataSource to bReverseOrdering
   162        Set pbDDReadMode of hoDataSource to bDDReadMode
   163        Set pbStaticData of hoDataSource to bStatic
   164        Set pbLoadAll of hoDataSource to bStatic
   165    End_Procedure
   166
   167    { NoDoc=True }
   168    Procedure Add_Focus Handle hoParent Returns Integer
   169        Integer iRows
   170        Handle hoDataSource
   171        Boolean bAutoLoad bAllLoaded bActive
   172        Forward Send Add_Focus hoParent
   173        
   174        // server.pkg has an add_focus. This is what we need from it.
   175        Get Active_State to bActive
   176        If (bActive) Begin
   177            Send Attach_Deo_To_Server
   178            Send DataLoadAdjustOnAddFocus
   179        End
   180    End_Procedure
   181    
   182    { Visibility=Private }
   183    Procedure DataLoadAdjustOnAddFocus
   184        Integer iRows
   185        Handle hoDataSource hoServer
   186        Boolean bAllLoaded bHasRec
   187        RowID riID
   188
   189        Get Server to hoServer
   190        Get HasRecord of hoServer to bHasRec
   191        Get phoDataSource to hoDataSource
   192        Get RowCount of hoDataSource to iRows
   193        Get AllDataIsLoaded of hoDataSource to bAllLoaded
   194        
   195        If (iRows=0 and not(bAllLoaded) and bHasRec) Begin
   196            Send RefreshDataFromDD riID 0
   197        End
   198    End_Procedure
   199    
   200    { NoDoc=True }
   201    Procedure OnIdle
   202        Boolean bUnOrdered bNew bRegenerate bStatic bChanged bBeginEdit
   203        Handle hoDataSource
   204        
   205        // set pbBeginEditOnIdle false before forwarding, so the grid will not start edit mode on us.
   206        // We wll do the BeginEditOnIdle here at the very end.
   207        Get pbBeginEditOnIdle to bBeginEdit
   208        Set pbBeginEditOnIdle to False
   209        Forward Send OnIdle
   210        
   211        Get pbUnOrdered to bUnOrdered
   212        Get pbAutoRegenerate to bRegenerate
   213        Get pbStaticData to bStatic
   214        If (bUnOrdered and bRegenerate and not(bStatic)) Begin
   215            Get phoDataSource to hoDataSource
   216            Get IsSelectedRowNew of hoDataSource to bNew
   217            Get ShouldSaveSelectedRow of hoDataSource to bChanged
   218            // If row is new we are still in add mode - no refresh
   219            // If row is changed it is not safe to refresh because you will lose changes
   220            If (not(bNew) and not(bChanged)) Begin
   221                Send RefreshDataFromSelectedRow
   222            End
   223        End
   224        // restore pbBeginEditOnIdle and do the end of idle activation.
   225        Set pbBeginEditOnIdle to bBeginEdit
   226        Send BeginEditOnIdle
   227    End_Procedure
   228    
   229    // augment to refresh the grid if it is unordered after a save. Generally upon
   230    // exit we want to grid refreshed else OnIdle may do this when the grid does not have 
   231    // the focus which can change other DEOs that rely on this grid.
   232    { NoDoc=True }
   233    Procedure Exiting Handle hoDestination Returns Integer
   234        Boolean bCancel bUnOrdered bNew bChanged bRegenerate bStatic
   235        Handle hoDataSource hoEdit
   236        
   237        Forward Get msg_Exiting hoDestination to bCancel
   238        
   239        // if we moving to the custom edit control, we don't want to do any exiting - it's internal
   240        Get phoCustomEdit to hoEdit
   241        If ( (hoEdit<>0 and hoEdit=hoDestination)) Begin
   242             Procedure_Return False
   243        End
   244        
   245        If (not(bCancel)) Begin
   246            Get pbUnOrdered to bUnOrdered
   247            Get pbAutoRegenerate to bRegenerate
   248            Get pbStaticData to bStatic
   249            If (bUnOrdered and bRegenerate and not(bStatic)) Begin
   250                Get phoDataSource to hoDataSource
   251                Get IsSelectedRowNew of hoDataSource to bNew
   252                Get ShouldSaveSelectedRow of hoDataSource to bChanged
   253                // if the row is refreshable, we will refresh
   254                If (not(bNew) and not(bChanged)) Begin
   255                    Send RefreshDataFromSelectedRow
   256                End
   257            End
   258        End
   259        Procedure_Return bCancel
   260    End_Procedure
   261    
   262    
   263    // required DD/DEO Find interface
   264    Procedure Request_Find Integer eFindMode Integer bEntUpdt
   265        Integer iCol                
   266        Get SelectedColumn to iCol
   267        If (iCol<>-1) Begin
   268            Send RequestColumnFind iCol eFindMode bEntUpdt
   269        End
   270    End_Procedure
   271
   272    // required DD/DEO Find interface
   273    Procedure Find_GE
   274        Send Request_Find GE True
   275    End_Procedure
   276    
   277    // required DD/DEO Find interface
   278    Procedure Find_Next
   279        Send Request_Find GT True
   280    End_Procedure
   281    
   282    // required DD/DEO Find interface
   283    Procedure Find_Previous
   284       Send Request_Find LT True
   285    End_Procedure
   286    
   287    // required DD/DEO Find interface
   288    Procedure Find_First
   289        Send Request_Find FIRST_RECORD False // param is false because entry-update is not needed
   290    End_Procedure
   291    
   292    // required DD/DEO Find interface
   293    Procedure Find_Last
   294        Send Request_Find LAST_RECORD False
   295    End_Procedure
   296    
   297    
   298    // required DD/DEO interface
   299    // sent by DD before a find and save. We only care about DD finds which
   300    // means DoAll is 1
   301    { Visibility=Private }
   302    Procedure Entry_update Integer iFile Integer iDoAll
   303        Handle hoDataSource
   304        If (iDoAll=1) Begin
   305            Get phoDataSource to hoDataSource
   306            // we pass file number as our flag. This is used to only update the data
   307            // for this one file.
   308            Send SynchronizeDataForSelectedRow of hoDataSource True iFile
   309        End
   310    End_Procedure
   311
   312    Procedure Request_Clear_All
   313        Boolean bErr
   314        Handle hoServer
   315        Send Request_ClearRow // restores previous row which may trigger data-loss warning and cancel
   316        Move (Err) to bErr
   317        If not bErr Begin
   318            Get Server to hoServer
   319            Send Clear_All to hoServer
   320            Send Beginning_of_Panel            
   321        End
   322    End_Procedure
   323    
   324    // A grid save *is* a no-clear save so you don't really need to use this. However this message is supported in DEO controls
   325    // and we want it to work if this is sent from a hot-key, menu or toolbar item.
   326    Procedure Request_Save_No_Clear
   327        Send Request_Save
   328    End_Procedure
   329
   330    // returns the table's status for the refresh event. A table can either be
   331    // cleared, found or not touched by the operation. This can only be called while
   332    // within Refresh. This was created to hide the private is_file_included command
   333    Function DDRefreshTableStatus Integer iTable Returns Integer
   334        Boolean bIncluded
   335        is_file_included iTable 1 to bIncluded // see if main file is in find done array
   336        If bIncluded Begin
   337            Function_Return ddrtsFound
   338        End
   339        is_file_included iTable 0 to bIncluded // see if main file is in clear done array
   340        If bIncluded Begin
   341            Function_Return ddrtsCleared
   342            
   343        End
   344        Function_Return ddrtsNone
   345    End_Function
   346
   347
   348
   349    // required DD/DEO interface
   350    // sent by DD when there is a clear/find/save/delete
   351    { MethodType=Event }
   352    Procedure Refresh Integer eMode
   353        Handle hoDataSource hoDD hoCol
   354        Boolean bRowDisplay bMainFound bDeferred
   355        Integer iMainFile iRow iSel iOffSet eDDStatus
   356        RowID riId
   357        
   358        If not (active_state(Self)) Begin
   359            Procedure_Return
   360        End
   361
   362        Get Deferred_State to bDeferred
   363        If (bDeferred) Begin
   364            Procedure_Return
   365        End
   366        
   367        
   368        Get Server to hoDD
   369        Get phoDataSource to hoDataSource
   370        Get Main_File of hoDD to iMainFile
   371        Get SelectedRow of hoDataSource to iSel
   372        
   373        Get DDRefreshTableStatus iMainFile to eDDStatus
   374        Move (eDDStatus<>ddrtsNone) to bMainFound // T=main dd find or constrained child dd find
   375
   376        // if the datasource is notifying the DD of a change, this is only a local row change
   377        Get pbNotifyingExternalDD of hoDataSource to bRowDisplay
   378        
   379        // If no selected row and we've done a save or delete on the main file, we don't know what to do so we will refresh the grid
   380        // This could happen if the save is occuring from an external source (e.g., create a new record directly in the DD).
   381        If (iSel=-1 and (eMode=MODE_SAVE or eMode=MODE_DELETE) and bMainFound and (not(bRowDisplay))) Begin
   382            Move MODE_FIND_OR_CLEAR_SET to eMode
   383        End
   384
   385        If (eMode=MODE_CLEAR and bMainFound) Begin
   386            
   387            // special case with clear. If this comes from some other DEO (which is unusual)
   388            // and the curent row has a record, then we need to insert a row for the
   389            // cleared row.
   390            If (iSel<>-1) Begin
   391                Get RowTag of hoDataSource iSel to riId
   392                If (not((IsNullRowID(riID)))) Begin
   393                    Send InsertRow of hoDataSource iSel
   394                    Send SelectRow of hoDataSource iSel False
   395                    Send SynchronizeGridtoSelectedRow ropTop
   396                End
   397            End
   398            
   399            Send SynchronizeDataForSelectedRow of hoDataSource False eMode
   400        End
   401        
   402        Else If (eMode=MODE_DELETE or eMode=MODE_SAVE or bRowDisplay or not(bMainFound)) Begin
   403
   404            Send SynchronizeDataForSelectedRow of hoDataSource False eMode
   405            // if a save notification and the save's DD is the same as the grid's
   406            // we are saving the main record and it may now be out of order
   407            If (eMode=MODE_SAVE and (hoDD=OPERATION_ORIGIN)) Begin
   408                Set pbUnOrdered to True
   409            End
   410        End
   411        
   412        Else If (eMode=MODE_FIND_OR_CLEAR_SET or eMode=MODE_CLEAR_ALL) Begin
   413            // if here this is a refresh the entire grid
   414            Send EndEdit
   415            Send LockBeginEdit // we cannot allow the edit to be activated during refresh 
   416            Get OffSetFromTop to iOffset
   417            Move (GetRowID(iMainFile)) to riId
   418            Get LoadByMatchingRow riId True to iRow
   419            //Synchronize Grid selectRow/Selectcol with datasource (don't recurse in rowchangng)
   420            Send SelectRow of hoDataSource iRow False
   421            Send SynchronizeGridtoSelectedRow iOffSet
   422            Send ReadByRowId of hoDD iMainFile riId
   423            Send UnlockBeginEdit
   424            // this may popup the edit control but we cannot allow that to happen within a refresh event
   425            Set pbBeginEditOnIdle to True
   426        End
   427        Else Begin
   428            Procedure_Return
   429        End
   430        
   431        Send DeferredRedraw
   432    End_Procedure
   433    
   434    // required DD/DEO interface
   435    // sent by DD whenever DD value has changed. 
   436    { Visibility=Private }
   437    Procedure File_Field_Value_Changed Integer iFile Integer iField String sValue Integer iChangeDisabled
   438        Integer iCols i
   439        Handle hoCol hoDataSource
   440        Boolean bChanged bFieldChanged
   441        Get ColumnCount to iCols
   442        Get phoDataSource to hoDataSource
   443        // send to all columns
   444        For i from 0 to (iCols-1)
   445            Get DEOColumnObject i to hoCol
   446            If hoCol Begin
   447                Get FileFieldValueChanged of hoCol iFile iField sValue iChangeDisabled to bFieldChanged
   448                Move (bFieldChanged or bChanged) to bChanged
   449            End
   450        Loop
   451        If (bChanged) Begin
   452            Send DeferredRedraw
   453        End
   454    End_Procedure
   455    
   456    // required DD/DEO interface
   457    // sent by DD whenever DD option has changed. 
   458    { Visibility=Private }
   459    Procedure File_Field_Option_Changed integer iFile integer iField integer iOptions integer bClear
   460        Integer iCols i
   461        Handle hoCol
   462        Get ColumnCount to iCols
   463        // send to all columns
   464        For i from 0 to (iCols-1)
   465            Get DEOColumnObject i to hoCol
   466            If hoCol Begin
   467                Send FileFieldOptionChanged of hoCol iFile iField iOptions bClear
   468            End
   469        Loop
   470    End_Procedure
   471
   472    // required DD/DEO interface
   473    { Visibility=Private }
   474    Procedure File_Field_mask_Changed Integer iFile Integer iField String sMask
   475        Integer iCols i
   476        Handle hoCol
   477        Get ColumnCount to iCols
   478        // send to all columns
   479        For i from 0 to (iCols-1)
   480            Get DEOColumnObject i to hoCol
   481            If hoCol Begin
   482                Send FileFieldMaskChanged of hoCol iFile iField sMask
   483            End
   484        Loop
   485    End_Procedure
   486
   487    // required DD/DEO interface
   488    { Visibility=Private }
   489    Procedure File_Field_Label_Changed Integer iFile Integer iField Boolean bLong String sLabel
   490        Integer iCols i
   491        Handle hoCol
   492        Get ColumnCount to iCols
   493        // send to all columns
   494        For i from 0 to (iCols-1)
   495            Get DEOColumnObject i to hoCol
   496            If hoCol Begin
   497                Send FileFieldLabelChanged of hoCol iFile iField bLong sLabel
   498            End
   499        Loop
   500    End_Procedure
   501
   502    
   503    // required DD/DEO interface
   504    { Visibility=Private }
   505    Function Item_Field_Property Integer iMsg Integer iItem Returns String
   506        Integer iFile iField
   507        Handle hoDD
   508        String sValue
   509        
   510        Get Server to hoDD
   511        Get Data_File iItem to iFile
   512        If iFile Begin
   513            Get Data_Field iItem to iField
   514            Get iMsg of hoDD iFile iField to sValue
   515        End
   516        Function_Return sValue
   517    End_Function
   518
   519    // required DD/DEO interface
   520    // sent by DD to commit the focused value
   521    { Visibility=Private }
   522    Procedure Update_focus_field
   523        Send CommitFocusField
   524    End_Procedure
   525    
   526    // required DD/DEO interface
   527    { Visibility=Private }
   528    Function Validate_Items Boolean bNotFindReq Returns Integer
   529    End_Function
   530    
   531    { Visibility=Private }
   532    Function ItemToDEOColumnObject Integer iItem Returns Handle
   533        Handle hoCol
   534        If (iItem<>-1) Begin
   535            If (iItem=Current) Begin
   536                Get SelectedColumn to iItem
   537                If (iItem=-1) Begin
   538                    Function_Return 0
   539                End
   540            End
   541            // note ths returns 0 if this is not a DEO column
   542            Get DEOColumnObject iItem to hoCol
   543        End
   544        Function_Return hoCol
   545    End_Function
   546    
   547    // required DD/DEO interface
   548    Function Data_File Integer iItem Returns Integer
   549        Integer iFile 
   550        Handle hoCol
   551        Get ItemToDEOColumnObject iItem to hoCol
   552        If (hoCol) Begin
   553            Get piBindingTable of hoCol to iFile
   554        End
   555        Function_Return iFile
   556    End_Function
   557
   558    // required DD/DEO interface
   559    Function Data_Field Integer iItem Returns Integer
   560        Integer iField
   561        Handle hoCol
   562        Get ItemToDEOColumnObject iItem to hoCol
   563        If (hoCol) Begin
   564            Get piBindingColumn of hoCol to iField
   565        End
   566        Function_Return iField
   567    End_Function
   568    
   569    // required DD/DEO interface
   570    { Visibility=Private }
   571    Function Checkbox_item_State Integer iItem Returns Integer
   572        Integer iState
   573        Handle hoCol
   574        Get ItemToDEOColumnObject iItem to hoCol
   575        If (hoCol) Begin
   576            Get pbCheckbox of hoCol to iState
   577        End
   578        Function_Return iState
   579    End_Function
   580    
   581    // required DD/DEO interface
   582    { Visibility=Private }
   583    Function Item_Noput Integer iItem Returns Integer
   584        Integer iState
   585        Handle hoCol
   586        Get ItemToDEOColumnObject iItem to hoCol
   587        If (hoCol) Begin
   588          Get DDNoput of hoCol to iState
   589        End
   590        Function_Return iState
   591    End_Function
   592    
   593    // required DD/DEO interface
   594    { Visibility=Private }
   595    Function Data_Value Integer iItem Returns String
   596        Handle hoCol
   597        String sValue
   598        Get ItemToDEOColumnObject iItem to hoCol
   599        If (hoCol) Begin
   600            Get SelectedRowValue of hoCol to sValue
   601        End
   602        Function_Return sValue
   603    End_Function
   604    
   605    // required DD/DEO interface
   606    { Visibility=Private }
   607    Function prototype_object Returns Handle
   608        Function_Return Self
   609    End_Function
   610    
   611    // required DD/DEO interface
   612    { Visibility=Private }
   613    Procedure update_dependent_items
   614    End_Procedure
   615
   616    // required DD/DEO interface
   617    Function Extended_deo_State Returns Integer
   618        Function_Return True
   619    End_Function
   620    
   621    // required DD/DEO interface
   622    Function Deo_Find_Object Returns Boolean
   623       Function_Return True
   624    End_Function  
   625    
   626    // required DD/DEO interface
   627    Function DEO_Control_Object Returns Boolean
   628        Function_Return True
   629    End_Function  
   630    
   631    // required DD/DEO interface
   632    Function DEO_Object Returns Boolean
   633        Function_Return True
   634    End_Function  
   635
   636    // required DD/DEO interface
   637    { Visibility=Private }
   638    Procedure Copy_Item_Options Integer iDSO Integer iFile Integer iField Integer iDEO Integer iItem
   639        Handle hoCol
   640        Get DEOColumnObject iItem to hoCol
   641        If hoCol Begin
   642            Send CopyDDFieldOptions of hoCol iDSO
   643        End
   644    End_Procedure
   645
   646    
   647    // returns object for column. If the column object is not a DEO it returns 0
   648    Function DEOColumnObject Integer iColumn Returns Handle
   649        Handle hoCol
   650        Boolean bDEO
   651        Get ColumnObject iColumn to hoCol
   652        If (hoCol) Begin
   653            
   654            Get DEO_Object of hoCol to bDEO
   655            If not bDEO Begin
   656                Move 0 to hoCol
   657            End
   658        End
   659        Function_Return hoCol
   660    End_Function
   661    
   662    
   663    Procedure RequestColumnFind Integer iCol Integer eFindMode Integer bEntUpdt
   664        Integer iFile iField iIndex iMain iOffset iRelField eRequestFindMode
   665        Boolean bDDReadMode bFound bStatic
   666        Handle hoCol hoServer hoDataSource
   667        
   668        Get peRequestFindMode to eRequestFindMode
   669        
   670        // if finding not allowed at all
   671        If (eRequestFindMode=rfmFindNone) Begin
   672            Move False to Found
   673            Procedure_Return
   674        End
   675
   676        Get DEOColumnObject iCol to hoCol
   677        If (hoCol=0) Begin
   678            Move False to Found
   679            Procedure_Return
   680        End
   681
   682        Get phoDataSource to hoDataSource
   683        Get DataIsStatic of hoDataSource to bStatic
   684        Get piBindingTable of hoCol to iFile
   685        Get piBindingColumn of hoCol to iField
   686        Get Server to hoServer
   687        Get Main_File of hoServer to iMain
   688        If (iFile=0) Begin
   689            Move False to Found
   690            Procedure_Return
   691        End
   692
   693        Get File_Field_Index of hoServer iFile iField to iIndex
   694        If (iIndex=-1) Begin
   695            Move False to Found
   696            Procedure_Return
   697        End
   698            
   699        Get Deferred_State to bDDReadMode
   700
   701        // if this is a main file find we will ignore it if main-file finds are
   702        // not allowed or the grid is static. If Static, you should not be doing finds
   703        // on the mainfile as it will cause the data to all be reloaded.
   704        If (iFile=iMain and ( (eRequestFindMode=rfmFindParentOnly) or bStatic) ) Begin
   705            Move False to Found
   706            Procedure_Return
   707        End
   708        // if main or find all or findparentonly (with a parent find)
   709        Else If (iFile=iMain or eRequestFindMode=rfmFindAll or eRequestFindMode=rfmFindParentOnly ) Begin
   710            Send EndEdit
   711            Send Item_Find of hoServer eFindMode iFile iField bEntUpdt True bDDReadMode
   712            Move (Found) to bFound
   713        End
   714        // if parent with find mainonly
   715        Else If (eRequestFindMode=rfmFindMainOnly) Begin
   716           Move False to Found
   717           Procedure_Return 
   718        End
   719        // is parent with find superfind logic (used by prompt lists)
   720        Else Begin
   721           Get RelatingField iFile to iRelField
   722           If (iRelField=0) Begin
   723               Move False to Found
   724               Procedure_Return   
   725           End
   726           Send EndEdit
   727           Send Item_Find of hoServer eFindMode iFile iField bEntUpdt True bDDReadMode
   728           Move (Found) to bFound
   729           If ( (bFound) ) Begin
   730                Send Item_Find to hoServer GE iMain iRelField bEntUpdt True bDDReadMode
   731                Move (Found) to bFound
   732           End
   733        End
   734        
   735        // handles deferred finds, which only make sense with main file finds
   736        If (bFound and bDDReadMode and (iFile=iMain)) Begin
   737            Get OffSetFromTop to iOffset
   738            Send RefreshDataFromExternal iOffset
   739        End
   740        Move bFound to Found
   741            
   742    End_Procedure
   743
   744    // Attempt to find the field from the server's MainFile that relates to iRelatedFile
   745    { Visibility=Private }
   746    Function RelatingField Integer iRelatedFile Returns Integer
   747        Integer iField iRelFile iNumFields iIndex iMainfile
   748        Handle hoServer
   749        Get Server to hoServer
   750        Get Main_File of hoServer to iMainfile
   751        Get_Attribute DF_FILE_NUMBER_FIELDS of iMainFile to iNumFields
   752        For iField from 1 to iNumFields
   753            // find first field that relates to the related file and has an index.
   754            Get_Attribute DF_FIELD_RELATED_FILE of iMainFile  iField to iRelFile
   755            If (iRelFile=iRelatedFile) Begin
   756                Get_Attribute DF_FIELD_INDEX of iMainFile iField to iIndex
   757                If (iIndex>0) Begin
   758                    Function_Return iField
   759                End
   760            End
   761        Loop
   762        Function_Return -1
   763    End_Function
   764
   765
   766    // does a find for the passed column by first looking down and, if no find, then looking up
   767    // This is used when you are doing lookup/searches
   768    Procedure RequestColumnLookup Integer iCol
   769        // we are counting on RequestColumnFind returning the FOUND indicator propery set
   770        Send RequestColumnFind iCol GE True iCol
   771        If (not(Found)) Begin
   772            // if not found, we will attempt to find the first record in the other direction. This
   773            // should be the last record. This keeps selection lists from ending up with a
   774            // invalid value in the list after a failed selection. This can probably only happen
   775            // when DD constraints are in place
   776            Send RequestColumnFind iCol LE True
   777        End
   778    End_Procedure
   779    
   780    { NoDoc=True }
   781    Procedure HeaderReorder Integer iCol
   782        Handle hoCol hoDataSource
   783        Integer iOrder iOld iOldCol
   784        Boolean bHeaderTogglesDirection bHeaderReorders bReverse bStatic bLoaded
   785        Get phoDataSource to hoDataSource
   786        Get DataIsStatic of hoDataSource to bStatic
   787        If bStatic Begin
   788            Get AllDataIsLoaded of hoDataSource to bLoaded
   789            If bLoaded Begin
   790                Forward Send HeaderReorder iCol
   791            End
   792        End
   793        Else Begin
   794            Get DEOColumnObject iCol to hoCol
   795            If hoCol Begin
   796                Get pbHeaderTogglesDirection to bHeaderTogglesDirection
   797                Get pbHeaderReorders to bHeaderReorders
   798                If bHeaderReorders Begin
   799                    Get ColumnOrdering of hoCol to iOrder
   800                    If (iOrder>=0) Begin
   801                        Get Ordering to iOld
   802                        Get piSortColumn to iOldCol
   803                        If (iOldCol<>iCol or iOrder<>iOld) Begin
   804                            Send ReorderGridByColumn hoCol False
   805                        End
   806                        Else If bHeaderTogglesDirection Begin
   807                            Get pbReverseOrdering to bReverse
   808                            Send ReorderGridByColumn hoCol (not(bReverse))
   809                        End
   810                    End
   811                End
   812            End
   813        End
   814    End_Procedure
   815    
   816    Procedure ReorderGridByColumn Handle hoCol Boolean bDescending
   817        Integer iCol iOrdering
   818        Get ColumnOrdering of hoCol to iOrdering
   819        If (iOrdering>=0) Begin
   820            Get piColumnId of hoCol to iCol
   821            Set piSortColumn to iCol
   822            Send ChangeOrdering iOrdering bDescending
   823        End
   824    End_Procedure
   825    
   826    Procedure ChangeOrdering Integer iOrdering Boolean bDescending
   827        Boolean bCancel
   828        
   829        // commit any changes in row first
   830        Get CommitSelectedRow to bCancel
   831        If bCancel Begin
   832            Function_Return True
   833        End
   834                
   835        Set pbReverseOrdering to bDescending
   836        Set Ordering to iOrdering
   837        
   838        // if com object not created this just sets it up for the next activation
   839        If (IsComObjectCreated(Self)) Begin
   840            Send BindDataSource
   841            Send RefreshDataFromSelectedRow
   842        End
   843    End_Procedure
   844    
   845    // Load grid based on rowId. If bResetCache the cache is cleared so the
   846    // search always refreshed. If false, it tries to find the ID in the existing 
   847    // datasource first.
   848    { Visibility=Private }
   849    Function LoadByMatchingRow RowID riID Boolean bResetCache Returns Integer
   850        Handle hoDataSource
   851        Integer iCount iIndex
   852        Boolean bDirty
   853        
   854        Get phoDataSource to hoDataSource
   855        
   856        If bResetCache Begin
   857            Send Reset of hoDataSource
   858        End
   859        
   860        Get PageInMatchingRow of hoDataSource riID to iIndex
   861        If (iIndex=-1) Begin
   862            Send Reset of hoDataSource
   863        End
   864        Else Begin
   865            Get DataSourceSynchRequired of hoDataSource to bDirty
   866        End
   867        If (iIndex=-1 or bDirty ) Begin
   868            Send SelectRow of hoDataSource -1 True
   869            Send ReSynchToDataSource
   870        End
   871     
   872        Set pbUnOrdered to False
   873        Function_Return iIndex
   874    End_Procedure
   875    
   876    // Refreshes grid around this row id. Allows you to refresh a grid around record.
   877    // This always refreshes the cache
   878    Procedure RefreshDataFromMatchingRow RowID riID Integer iOffset
   879        Integer iRow
   880        Handle hoDataSource
   881        Get phoDataSource to hoDataSource
   882        Get LoadByMatchingRow riID True to iRow
   883        If (iRow<>-1) Begin         
   884            Send SelectRow of hoDataSource iRow True
   885            Send SynchronizeGridtoSelectedRow iOffset
   886        End
   887    End_Procedure
   888    
   889    // Refreshes grid around selected row id
   890    Procedure RefreshDataFromSelectedRow
   891        RowID riID 
   892        Integer iSel iOffset
   893        Handle hoDataSource
   894        Get phoDataSource to hoDataSource
   895        Get SelectedRow of hoDataSource to iSel
   896        If (iSel<>-1) Begin
   897            Get OffSetFromTop to iOffset
   898            Get RowTag of hoDataSource iSel to riID
   899            Send RefreshDataFromMatchingRow riID iOffset
   900        End
   901    End_Procedure
   902
   903    // Refreshes grid around the DD record. You'd use this if you've got a newly empty activated grid or a
   904    // deferred grid
   905    // This always refreshes the cache
   906    Procedure RefreshDataFromDD Integer iOffset
   907        RowID riID 
   908        Handle hoDD
   909        Get Server to hoDD
   910        Get CurrentRowId of hoDD to riID
   911        Send RefreshDataFromMatchingRow riID iOffset
   912    End_Procedure
   913
   914    // Refreshes grid around the current file buffer
   915    // This always refreshes the cache
   916    Procedure RefreshDataFromExternal Integer iOffset
   917        RowID riID 
   918        Handle hoDD
   919        Integer iFile
   920        Get Server to hoDD
   921        Get Main_File of hoDD to iFile
   922        Move (GetRowID(iFile)) to riID
   923        Send RefreshDataFromMatchingRow riID iOffset
   924    End_Procedure
   925    
   926    // do a popup search request for the passed column. The keys can provide a
   927    // seed value - they come from OnComKeyDown. Augmented to do a file find with
   928    // DB grids
   929    { NoDoc=True }
   930    Procedure RequestColumnSearch Handle hoCol  Integer iKeyCode Integer iKeyShift
   931        Handle hoSearchDialog hoDataSource
   932        Integer iCol
   933        Boolean bOk bStatic
   934        String sValue
   935
   936        Get piColumnId of hoCol to iCol
   937        Get Create (RefClass(cCJGridSearchDialog)) to hoSearchDialog
   938        Get RequestGridSearch of hoSearchDialog iKeyCode iKeyShift hoCol (&sValue) to bOk
   939        If bOk Begin
   940          Get phoDataSource to hoDataSource  
   941          Get DataIsStatic of hoDatasource to bStatic
   942          If bStatic Begin
   943              Send RequestFindColumnValue iCol sValue True 0  
   944          End
   945          Else Begin
   946              Send UpdateCurrentValue of hoCol sValue
   947              Send RequestColumnLookup iCol
   948          End
   949        End
   950        Send Destroy of hoSearchDialog
   951    End_Procedure
   952    
   953End_Class
   954