Module cDbCJGridColumn.pkg

     1Use UI
     2Use cCJReportControl.pkg
     3Use cCJGridColumn.pkg
     4Use cDbCJGridColumnEdit.pkg
     5Use cDbCJGridDataSource.pkg
     6
     7
     8{ HelpTopic=cDbCJGridColumn }
     9{ OverrideProperty=psLicenseKey DesignTime=False }
    10{ OverrideProperty=psProgID DesignTime=False }
    11{ DataBindable=True}
    12Class cDbCJGridColumn is a cCJGridColumn
    13
    14    Procedure Construct_Object
    15        tGridComboHelper GridComboHelper
    16
    17        Forward Send Construct_Object 
    18
    19        Set phcEditClass to (RefClass(cDbCJGridColumnEdit))
    20
    21        {Visibility=Private}
    22        Property tGridComboHelper pGridComboHelper // used with combo lists
    23
    24        { Category=Behavior } 
    25        Property Boolean Auto_Label_State False
    26
    27        Move CB_CODE_DISPLAY_DESCRIPTION to GridComboHelper.eCodeDisplay // default value
    28        Move True to GridComboHelper.bDataOnly // default. May be changed when item is added
    29        Set pGridComboHelper to GridComboHelper
    30        
    31    End_Procedure
    32
    33    // Can be used to determine if the column object understands teh DEO interface
    34    { NoDoc = True }
    35    Function DEO_Object Returns Boolean
    36        Function_Return True
    37    End_Function  
    38
    39
    40    // augment to set the edit's bindng and column
    41    {Visibility=Private }
    42    Function CustomEditObject Returns Handle
    43         Handle hoEdit
    44         Integer iTable iColumn
    45         Forward Get CustomEditObject to hoEdit
    46         If (hoEdit) Begin
    47             Get piBindingTable to iTable
    48             Set Data_File of hoEdit to iTable
    49             Get piBindingColumn to iColumn
    50             Set Data_Field of hoEdit to iColumn
    51         End
    52         Function_Return hoEdit
    53    End_Function
    54    
    55    { Visibility=Private }
    56    Function FileFieldValueChanged Integer iFile Integer iField String sValue Integer iChangeDisabled Returns Boolean
    57        Integer iTable iCol
    58        String sOldValue
    59        Boolean bError bIsEQ bDDReadMode
    60        
    61        // if this is deferred we do not respond to changes from the DD
    62        Get Deferred_State to bDDReadMode
    63        If bDDReadMode Begin
    64            Function_Return False
    65        End
    66
    67        Get piBindingTable to iTable
    68        Get piBindingColumn to iCol
    69        If (iTable=iFile and icol=iField) Begin
    70            Get SelectedRowValueBeforeEdit to sOldValue
    71            Send DataTypeEQTest sOldValue sValue (&bError) (&bIsEQ)
    72            If (not(bError) and not(bIsEQ)) Begin
    73                Send UpdateDataSourceForSelectedRow sValue False
    74                Function_Return True
    75            End
    76        End
    77        Function_Return False
    78    End_Function
    79
    80    // this is called by the datasource to move data to the DD buffer
    81    { Visibility=Private }
    82    Procedure UpdateDataToExternalSource String sValue Integer iUpdateFlag Integer iFlags
    83        Integer iDataTable iDataColumn
    84        Handle hODD
    85        Boolean bDDReadMode
    86
    87        Get Server to hODD  
    88        Get piBindingTable to iDataTable
    89        Get piBindingColumn to iDataColumn
    90        
    91        
    92        If (iUpdateFlag=ufUpdateToBuffer) Begin
    93
    94            // Update from the datasource to the global file buffer. Used for finds
    95            
    96            // iFlags is the file number and it should match the binding table
    97            If (hoDD and iDataTable>0 and iDataTable=iFlags) Begin
    98               Set_Field_Value iDataTable iDataColumn to sValue
    99            End
   100        End
   101        Else Begin // ufUpdateToDD
   102            
   103            // Update from the datasource to the DD's local field buffer. Used when data is changed
   104    
   105            // we never update with deferred grids. Actually the datasource should
   106            // protect against this and never call this method
   107            Get Deferred_State to bDDReadMode
   108            If bDDReadMode Begin
   109                Function_Return False
   110            End
   111    
   112            If (hoDD and iDataTable>0) Begin
   113                Set File_Field_Changed_Value of hoDD iDataTable iDataColumn to sValue
   114            End
   115        End
   116    End_Procedure
   117    
   118    {Visibility=Private }
   119    Function DDNoput Returns Boolean
   120        Handle hoServer
   121        Integer iFile iField iOpts
   122        Get Server to hoServer
   123        Get piBindingTable to iFile
   124        Get piBindingColumn to iField
   125        If (hoServer and iFile) Begin
   126            Get File_field_options of hoServer iFile iField to iOpts
   127            Function_Return ( iOpts iand DD_NOPUT)
   128        End
   129    End_Function
   130    
   131    {Visibility=Private }
   132    Function DDSkipFound Returns Boolean
   133        Handle hoServer
   134        Integer iFile iField iOpts
   135        Get Server to hoServer
   136        Get piBindingTable to iFile
   137        Get piBindingColumn to iField
   138        If (hoServer and iFile) Begin
   139            Get File_field_options of hoServer iFile iField to iOpts
   140            Function_Return ( iOpts iand DD_SKIPFOUND )
   141        End
   142    End_Function
   143  
   144  
   145    // agumented to handle noput
   146    { NoDoc=True }
   147    Procedure UpdateCurrentValue String sValue
   148        Handle hoDataSource hoServer
   149        Integer iRow iTable iTabColumn eAuto iOpts
   150        Boolean bNoPut bFindReq
   151        Get DDNoput to bNoPut
   152        Get piBindingTable to iTable
   153        Get piBindingColumn to iTabColumn
   154        Get phoDataSource to hoDataSource
   155        Get Server to hoServer
   156        Get SelectedRow of hoDataSource to iRow
   157        If (iRow<>-1) Begin
   158            If iTable Begin
   159
   160                // DEOs and DDs have a special rule with autofind and findreq. See notes in DD_deomx.pkg (Set Item_Changed_State) and
   161                // DataDict.pkg (Validate_FindReq) concerning setting field_changed_state. If noput, autofind and findreq, 
   162                // directly set the DD's field_changed_State. This is required to make autofind work.
   163                If bNoPut Begin
   164                    Get AutoFindMode to eAuto
   165                    Get File_Field_Options of hoServer iTable iTabColumn to iOpts
   166                    Move ((iOpts iand DD_FINDREQ)=DD_FINDREQ) to bFindReq
   167                    If (eAuto<>0 and bFindReq) Begin
   168                        Set File_Field_Changed_State of hoServer iTable iTabColumn to True
   169                    End
   170                end
   171
   172                If (not(bNoPut)) Begin  // if not noput, this is considered a change
   173                    // I've chosen to no set changed_state w/ noput here but not on input. There is less of a rule of
   174                    // consistency setting values here, so we will go with the smallest change. 
   175                    Set Changed_State to True
   176                End
   177            
   178            End
   179            
   180            Send UpdateDataSourceForSelectedRow sValue (not(bNoPut))
   181        End
   182    End_Procedure
   183
   184    // helper function to handle any Get File_Field_Xxxxx iFile iField to iVal message
   185    { Visibility=Private }
   186    Function ExecDDFieldIntFunction Integer iMsg Returns Integer
   187        Integer iFile iField iResult
   188        Handle hoDDO
   189        Get Server to hoDDO
   190        Get piBindingTable to iFile
   191        If (hoDDO and iFile) Begin
   192            Get piBindingColumn to iField
   193            Get Exec_File_Field_Message of hoDDO iFile iField iMsg to iResult
   194        End
   195        Function_Return iResult
   196    End_Function
   197
   198    // helper function to handle any Get File_Field_Xxxxx iFile iField to sVal message
   199    { Visibility=Private }
   200    Function ExecDDFileFieldStrFunction Integer iMsg Returns String
   201        Integer iFile iField
   202        Handle hoDDO
   203        String  sValue
   204        Get Server to hoDDO
   205        Get piBindingTable to iFile
   206        If (hoDDO and iFile) Begin
   207            Get piBindingColumn to iField
   208            Get iMsg of hoDDO iFile iField to sValue
   209        End
   210        Function_Return sValue
   211    End_Function
   212
   213    { Visibility=Private }
   214    Function Prompt_Object Returns Integer
   215        Handle hoPrompt
   216        Boolean bCheck bPromptList
   217        Get pbPromptListBehavior to bPromptList
   218        Forward Get Prompt_Object to hoPrompt
   219        If (hoPrompt=0 and not(bPromptList)) Begin
   220            Get ExecDDFileFieldStrFunction (RefFunc(File_Field_Prompt_Object)) to hoPrompt
   221            // checks to see if the checkbox is assigned to a validation table prompt. If it
   222            // is suppress it, it provides no useful information
   223            If (hoPrompt=DD_Global_Validation_Prompt_Object) Begin
   224                Get pbCheckbox to bCheck
   225                If bCheck Begin
   226                    Move 0 to hoPrompt
   227                End
   228            End
   229        End
   230        Function_Return hoPrompt
   231    End_Function
   232
   233    // this will be sent by the Entry_item command
   234    { Visibility=Private }
   235    Procedure Bind_Data Integer iFile Integer iField
   236        Set piBindingTable to iFile
   237        Set piBindingColumn to iField
   238    End_Procedure // Bind_Data
   239
   240    // this is sent when the grid is activated and the DD is binding this column for iFile and iField
   241    { Visibility=Private }
   242    Procedure CopyDDFieldOptions Handle hoDDO
   243        Handle hoServer
   244        Boolean bZero bLabel bCombo bPromptListBehavior
   245        String sName sToolTip
   246        Integer iFile iField iDDOptions        
   247        Integer eDisplayMode
   248        tGridComboHelper GridComboHelper
   249        
   250        Get piBindingTable to iFile
   251        Get piBindingColumn to iField
   252        Get pbPromptListBehavior to bPromptListBehavior
   253    
   254        Get pbComboButton to bCombo
   255        If bCombo Begin
   256            Send ComboFillList
   257            Set pbVDFEditControl to False
   258        End
   259
   260        Get File_Field_Options of hoDDO iFile iField to iDDOptions
   261        // we don't want to allow all DDO options. The mask contains the bits that are legal
   262        Move (iDDOptions iand DD_DEO_MASK) to iDDOptions
   263        
   264        // NoEnter
   265        If (iDDOptions iand DD_NOENTER and (not(bPromptListBehavior))) Begin
   266            Set pbEditable to False
   267            Set pbFocusable to False
   268        End
   269        
   270        // Capslock
   271        If (iDDOptions iand DD_CAPSLOCK) Begin
   272            Set pbCapslock to True
   273        End
   274        
   275        // Mask with zero suppress
   276        Move (iDDOptions iand DD_ZERO_SUPPRESS) to bZero
   277        Send CopyDDMaskOptions hoDDO iFile iField bZero
   278       
   279        // auto-label
   280        Get Auto_Label_State to bLabel
   281        If (bLabel) Begin
   282            Get File_Field_Label of hoDDO iFile iField DD_LABEL_SHORT to sName
   283            Set psCaption to sName
   284        End 
   285        
   286        // handle tool tip for the header
   287        Get psToolTip to sToolTip
   288        If (Trim(sToolTip) = "") Begin    // only change the tooltip if it is not already set
   289            Get ExecDDFileFieldStrFunction (RefFunc(File_Field_Status_Help)) to sToolTip
   290            Set psToolTip to sToolTip
   291        End
   292
   293        // If combo - augment to unset capslock if the display mode is not Code. If not code display the data that is displayed is
   294        // not the data being sent to the DD and it should not be capslocked by the DD. Also set a bigger form_margin.
   295        // You'd only need a big form_margin if entry_state is true which would be unlikely with a description combo (but it is supported).
   296        If bCombo Begin
   297            Get pGridComboHelper to GridComboHelper
   298            Get Code_Display_Mode to eDisplayMode
   299            If (eDisplayMode<>CB_CODE_DISPLAY_CODE and not(GridComboHelper.bDataOnly)) Begin
   300                Set pbCapslock to False // this might be been set true by the forward send of this message
   301                Set peDataType to ASCII_WINDOW // If display description-- make it a string
   302            End
   303        End
   304        
   305    End_Procedure
   306    
   307    { Visibility=Private }
   308    Procedure CopyDDMaskOptions Handle hoDDO Integer iFile Integer iField Boolean bZero
   309        Integer iMaskType iFieldType iFormType iFieldLen
   310        String  sMask
   311        
   312        // if mask type not manually set already. If mask-type is already assigned we assume
   313        // that both the mask and the type has been set and we will not change it.
   314        Get peDataType to iFormType // the datatype of the object/item
   315        If (iFormType<=ASCII_WINDOW) Begin
   316            Get_Attribute DF_FIELD_TYPE of iFile iField to iFieldType  // the type of the column
   317            Get File_Field_Mask_Type of hoDDO iFile iField to iMaskType // the type specified in the DD
   318            
   319            // if a mask is already defined in the DEO we will use that mask instead of
   320            // the one in the DD. We assume the developer knew what they were doing to
   321            // go to the extra trouble of creating a deo mask, yet no mask data-type.
   322            Get psMask to sMask // first see if we have local mask
   323            If (sMask="") Begin // only get DD mask if DEO mask is unassigned.
   324                Get File_Field_Mask      of hoDDO iFile iField to sMask // Get the mask for this
   325                Set psMask to sMask       
   326            End
   327            // if we have no type but we've got a mask or the form is string which we assume was not assigned - auto-assign it
   328            If (iMaskType=0 and (sMask<>"" or (iFormType=Ascii_Window))) Begin
   329                If (iFieldType=DF_DATE) Begin
   330                    Move Mask_Date_Window to iMaskType
   331                End
   332                Else If (iFieldType=DF_DATETIME) Begin
   333                    Move Mask_Datetime_Window to iMaskType
   334                End
   335                Else If (iFieldType=DF_BCD) Begin
   336                    Move Mask_Numeric_Window to iMaskType
   337                End
   338                // we change a string to a string mask only if there actually is a mask
   339                Else If (iFieldType=DF_ASCII and sMask<>"") Begin
   340                    Move Mask_Window to iMaskType
   341                End
   342                // if type is not one of the above will not apply an mask type
   343            End
   344            
   345            If (iMaskType>ASCII_WINDOW) Begin // if field mask type is set
   346                Set peDataType to iMaskType   // set mask type from ddo (might also set form mask)
   347                // if the mask is blank but the field type is numeric or currency
   348                // we will build an automatic mask based on our default mask
   349                If (iMaskType=MASK_NUMERIC_WINDOW or iMaskType=MASK_CURRENCY_WINDOW and  sMask='') Begin
   350                    Get Field_Number_Default_Mask iFile iField (If(iMaskType=Mask_Numeric_Window, Default_Numeric_Mask, Default_Currency_Mask)) to sMask
   351                    Set psMask to sMask       
   352                End
   353            End
   354            // if a non mask string we can set the max length
   355            Else If (iMaskType=0 and  iFormType=Ascii_Window and iFieldType=DF_ASCII) Begin
   356                Get_Attribute DF_Field_Length of iFile iField to iFieldLen
   357                Set piMaxLength to iFieldLen   
   358            End
   359        End
   360        // Now see if this item has a zero suppress set either by the DEO or (more likely) by
   361        // the DDO. If zero-suppress add a "Z" to first char of mask only if Z is not already there.
   362        If (bZero) Begin
   363            Get psMask to sMask // don't assume we know what sMask is.
   364            If ( (sMask<>"") and (Left(sMask,1)<>"Z") ) Begin
   365                Set psMask to ("Z"+sMask)
   366            End
   367        End
   368    End_Procedure
   369            
   370    // augment to send field entering message
   371    { Visibility=Private }
   372    Function Entering Returns Boolean
   373        Boolean bCancel bPromptList
   374        Get pbPromptListBehavior to bPromptList
   375        Get OnEntering to bCancel
   376        If (not(bCancel) and not(bPromptList)) Begin
   377            Get ExecDDFieldIntFunction (RefFunc(Field_Entry_msg)) to bCancel
   378        End
   379        Function_Return bCancel
   380    End_Function
   381    
   382    // augment to handle non-static combos
   383    { Visibility=Private }
   384    Procedure Entry
   385        Boolean bCombo bLoaded bStatic
   386        Handle hoTable
   387        
   388        // if a non static combo, we load data on entering
   389        Get pbComboButton to bCombo
   390        If bCombo Begin
   391            Get ExecDDFileFieldStrFunction (RefFunc(File_Field_Table_Object)) to hoTable
   392            If hoTable Begin
   393                Get Static_State of hoTable to bStatic
   394                Get Table_Loaded_State of hoTable to bLoaded
   395                If (not(bStatic) or not(bLoaded)) Begin
   396                    Send ComboFillList
   397                End
   398            End
   399        End
   400        
   401        Forward Send Entry
   402        
   403    End_Procedure
   404
   405    // augment to send field exiting message
   406    { Visibility=Private }
   407    Function Exiting Returns Boolean
   408        Boolean bCancel bPromptList
   409        Get pbPromptListBehavior to bPromptList
   410        Get OnExiting to bCancel
   411        If (not(bCancel) and not(bPromptList)) Begin
   412            Get ExecDDFieldIntFunction (RefFunc(Field_Exit_msg)) to bCancel
   413        End
   414        Function_Return bCancel
   415    End_Function
   416
   417    // augmented to do DD validaton
   418    { Visibility=Private }
   419    Function Validating Returns Boolean
   420        Integer iTable iColumn
   421        Handle hoServer
   422        Boolean bSelect bPromptList bCancel bChanged bFound
   423         
   424        Get pbPromptListBehavior to bPromptList
   425        Get Server to hoServer
   426        Get piBindingTable to iTable
   427        Get piBindingColumn to iColumn
   428        Get OnValidating to bCancel
   429        If (not(bCancel) and not(bPromptList) and hoServer and iTable) Begin
   430            // if we are here and the DD value is changed, it is possible that
   431            // this is an autofind that needs triggering. Since this is called before a save
   432            // it ensures that all autofind fields are autofound. Not that after a good autofind
   433            // the changed state for the field is cleared. Also note that special logic allows
   434            // noput/autofind/findreq to set Field_changed_state while a normal noput does not
   435            Get File_Field_Changed_State of hoServer iTable iColumn to bChanged
   436            If bChanged Begin
   437                Get DoAutoFind to bFound // DoAutoFind will only autofind actual autofind DD fields.
   438            End
   439            Get File_Field_Validate_Field of hoServer iTable iColumn to bCancel
   440        End
   441        Function_Return bCancel
   442    End_Function
   443
   444    // augmented to return value from DD
   445    { NoDoc=True }
   446    Function ValueToCheckedState String sValue Returns Boolean
   447        Integer iTable iColumn
   448        Handle hoServer
   449        Boolean bSelect
   450         
   451        Get Server to hoServer
   452        Get piBindingTable to iTable
   453        Get piBindingColumn to iColumn
   454        If (hoServer and iTable) Begin
   455            Get File_Field_Value_Select_State of hoServer iTable iColumn sValue to bSelect
   456        End
   457        Else Begin
   458            Forward Get ValueToCheckedState sValue to bSelect
   459        End
   460        Function_Return bSelect
   461    End_Function
   462
   463        
   464    // augmented to return value from DD
   465    { NoDoc=True }
   466    Function CheckedStateToValue Boolean bChecked Returns String
   467        Integer iTable iColumn
   468        Handle hoServer
   469        String sValue
   470         
   471        Get Server to hoServer
   472        Get piBindingTable to iTable
   473        Get piBindingColumn to iColumn
   474        If (hoServer and iTable) Begin
   475            Get File_Field_CheckBox_Value of hoServer iTable iColumn bChecked to sValue
   476        End
   477        Else Begin
   478            Forward Get CheckedStateToValue bChecked to sValue
   479        End
   480        Function_Return sValue
   481    End_Function
   482
   483    // return the autofind mode for the current item.
   484    // 0 = no autofind, 1 = autofind, 2 = autofind_ge
   485    { Visibility=Private }
   486    Function AutoFindMode Returns Integer
   487        Integer hoServer iFile iField iOpts bOn
   488
   489        Get piBindingTable to iFile
   490        Get piBindingColumn to iField
   491        Get Server to hoServer
   492        If (hoServer and iFile) Begin
   493            Get File_Field_Options of hoServer iFile iField to iOpts
   494            If ((iOpts iand DD_AUTOFIND_GE)=DD_AUTOFIND_GE) Function_Return 2
   495            Else If ((iOpts iand DD_AUTOFIND)=DD_AUTOFIND) Function_Return 1
   496        End
   497        Function_Return 0
   498    End_Function
   499
   500    // autofind if an autofind DD and the field is changed. As soon as a succuessful
   501    // autfoind occurs, the field is reset
   502    { Visibility=Private }
   503    Function DoAutoFind Returns Boolean
   504        Integer bChanged eAuto
   505        Integer hoServer iFile iField iOpts bOn iMain
   506        Handle hoDataSource
   507        Boolean bFound bDDReadMode bPromptList bStatic
   508
   509                
   510        // we don't do autofind with deferred grids. It makes no sense.
   511        Get Deferred_State to bDDReadMode
   512        Get pbPromptListBehavior to bPromptList
   513        If (bDDReadMode or bPromptList) Begin
   514            Function_Return False
   515        End
   516
   517        Get phoDataSource to hoDataSource
   518        Get DataIsStatic of hoDataSource to bStatic
   519        Get piBindingTable to iFile
   520        Get piBindingColumn to iField
   521        Get Server to hoServer
   522        Get Main_File of hoServer to iMain
   523        
   524        // Not using this for now. We will autofind on main file which is what the old
   525        // dbGrids did. This causes the entire grid to be rebuild. This causes up/down and mouse row navigations to do their
   526        // navigation after the change. 
   527        //    // With grids we will not support main file autofind.
   528        //    // If (hoServer and iFile and (iFile<>iMain)) Begin
   529        
   530        If (hoServer and iFile) Begin
   531            // if the data is static and this is a main file autofind we will not do the autofind. In other words,
   532            // main-file autofind is not supported with static grids.
   533            If (not(bStatic and (iFile=iMain))) Begin
   534                Get AutoFindMode to eAuto
   535                If (eAuto<>0) Begin
   536                    Send Item_Find to hoServer (If(eAuto=2,GE,EQ)) iFile iField True False False
   537                    // this message returns the found indicator if the find was ok
   538                    Move (Found) to bFound
   539                    Function_Return bFound
   540                End
   541            End
   542        End
   543        Function_Return False
   544    End_Function
   545
   546    // aumgmented to handle autofind. returns true if value is changed
   547    { Visibility=Private }
   548    Function NotifyEndEdit String sValue Returns Boolean
   549        String sOldValue
   550        Boolean bChanged bNewFind
   551        Forward Get NotifyEndEdit sValue to bChanged
   552        If bChanged Begin
   553           Get DoAutoFind to bNewFind
   554        End
   555        Function_Return (bChanged or bNewFind)
   556    End_Procedure
   557
   558    // aumgented to handle skipfound
   559    { NoDoc=True }
   560    Function CanNavigateIntoColumn Boolean bForward Returns Boolean
   561        Boolean bOk bSkipFound bRec bPromptList
   562        Handle hoServer
   563        Integer iTable iCol
   564        Get pbPromptListBehavior to bPromptList
   565        Forward Get CanNavigateIntoColumn bForward to bOk
   566        If (bOk and not(bPromptList)) Begin
   567           Get DDSkipFound to bSkipFound
   568           If bSkipFound Begin
   569               Get Server to hoServer
   570               Get piBindingTable to iTable
   571               Get Which_Data_Set of hoServer iTable to hoServer
   572               If (hoServer) Begin
   573                   Get HasRecord of hoServer to bRec
   574                   Move (not(bRec)) to bOk
   575               End
   576           End
   577        End
   578        Function_Return bOk
   579    End_Function
   580
   581
   582    // Called when initial value does not have binding table
   583    { MethodType=Event }
   584    Procedure OnSetCalculatedValue String ByRef sValue
   585    End_Procedure 
   586
   587    // called from datasource to provide a value. This assumes the
   588    // record or whatever is in place. Can be augmented to provide a
   589    // custom initial value
   590    { NoDoc=True }
   591    Function InitialValue Returns String
   592        Integer iDataCol iDataTab
   593        String sValue
   594        Get piBindingColumn to iDataCol
   595        Get piBindingTable to iDataTab
   596        If (iDataTab>0) Begin
   597            Get_Field_Value iDataTab iDataCol to sValue
   598            Move (Trim(sValue)) to sValue
   599        End
   600        Else Begin
   601            Send OnSetCalculatedValue (&sValue)
   602        End
   603        Function_Return sValue
   604    End_Function
   605    
   606    Function ColumnOrdering Returns Integer
   607        Integer iFile iField iFieldIndex iMainFile eRequestFindMode
   608        Handle hoServer
   609        Get peRequestFindMode to eRequestFindMode
   610        
   611        If (eRequestFindMode=rfmFindNone) Begin
   612            Function_Return -1                
   613        End
   614
   615        Get Server to hoServer
   616        Get piBindingColumn to iField
   617        Get piBindingTable  to iFile
   618        If (iFile>0) Begin
   619            Get Main_File of hoServer to iMainFile
   620            // if tables field is a parent field we might have a superfind relationship is allowed
   621            If (iFile<>iMainFile) Begin
   622                
   623                If (eRequestFindMode<>rfmFindMainSuper) Begin
   624                    Function_Return -1                
   625                End
   626                
   627                // first make sure that this parent field has an index, If not it cannot do an auto-index
   628                If (iField>0) Begin // if recnum, we have an index
   629                    Get_Attribute DF_FIELD_INDEX of iFile iField to iFieldIndex
   630                    If (iFieldIndex=0) Begin
   631                        Function_Return -1 // if none, return -1
   632                    End
   633                End
   634                // it has an index, now make that there is a relational link
   635                // between the main server file and this parent file. If not, no index
   636                Get RelatingField iFile to iField
   637            End
   638            If (iField=-1) Begin
   639                Function_Return -1
   640            End
   641            If (iField=0) Begin
   642                Function_Return 0
   643            End
   644            Get_Attribute DF_FIELD_INDEX of iMainFile iField to iFieldIndex
   645        End
   646        Function_Return (If(iFieldIndex=0,-1,iFieldIndex))
   647    End_Function
   648
   649
   650    // Combo related messages that connect the combo to a validation table
   651
   652    // aumgent to clear the data values in the helper object
   653    { NoDoc=True }
   654    Procedure ComboDeleteData
   655        tGridComboHelper GridComboHelper
   656        Forward Send ComboDeleteData
   657        Get pGridComboHelper to GridComboHelper
   658        Move (ResizeArray(GridComboHelper.sDataValues,0)) to GridComboHelper.sDataValues
   659        Set pGridComboHelper to GridComboHelper
   660    End_Procedure
   661
   662    // use the same interface here as other DEOs
   663    { MethodType=Property }
   664    Function Code_Display_Mode Returns Integer
   665        tGridComboHelper GridComboHelper
   666        Get pGridComboHelper to GridComboHelper
   667        Function_Return GridComboHelper.eCodeDisplay
   668    End_Function
   669
   670    { MethodType=Property }
   671    { Category=Appearance }
   672    { EnumList="CB_Code_Display_Description, CB_Code_Display_Code, CB_Code_Display_Both" }
   673    { InitialValue=CB_Code_Display_Description }
   674    Procedure Set Code_Display_Mode Integer eVal
   675        tGridComboHelper GridComboHelper
   676        Get pGridComboHelper to GridComboHelper
   677        Move eVal to GridComboHelper.eCodeDisplay
   678        Set pGridComboHelper to GridComboHelper
   679    End_Function
   680
   681    // For a column, pass data and return the description
   682    { Visibility=Private }
   683    Function ComboDataToDescription String sValue Returns String
   684        tGridComboHelper GridComboHelper
   685        tComboItemData[] ComboItemData
   686        Integer i iItems
   687
   688        Get pGridComboHelper to GridComboHelper
   689
   690        If (GridComboHelper.bDataOnly or GridComboHelper.eCodeDisplay=CB_CODE_DISPLAY_CODE) Begin
   691            Function_Return sValue
   692        End
   693
   694        // search for the data in our list of data values for this column
   695        Move (SizeOfArray(GridComboHelper.sDataValues)) to iItems
   696        For i from 0 to (iItems-1)
   697            If (GridComboHelper.sDataValues[i]=sValue) Begin
   698                Get ComboData to ComboItemData
   699                Function_Return ComboItemData[i].sCaption
   700            End
   701        End
   702
   703        // else if no match we will use the data as the description
   704        Function_Return sValue
   705    End_Function
   706
   707    // for a column, pass description and find the data
   708    { Visibility=Private }
   709    Function ComboDescriptionToData String sValue Returns String
   710        Integer iItem
   711        tGridComboHelper GridComboHelper
   712
   713        Get pGridComboHelper to GridComboHelper
   714
   715        // if data only, just return the data
   716        If (GridComboHelper.bDataOnly or GridComboHelper.eCodeDisplay=CB_CODE_DISPLAY_CODE) Begin
   717            Function_Return sValue
   718        End
   719
   720        // some kind of translation is needed. See if we have a match in our combo-list and then find the data value
   721        Get ComboFindItem 0 sValue to iItem
   722        If (iItem >= 0) Begin // if value is found
   723            Move GridComboHelper.sDataValues[iItem] to sValue
   724        End
   725        // else if not found, Just return the data (validation can be handled by the dd).
   726
   727        Function_Return sValue
   728    End_Function
   729
   730    // Public augmentation point. Pass current datavalue and all info
   731    // in record buffer. Should return what you want to see on the screen.
   732    // Augment to support various description/data Display formats.
   733    { MethodType=Event }
   734    Function ComboDescriptionValue Integer eMode String sDescVal String sDataVal Returns String
   735        If (eMode=CB_CODE_DISPLAY_CODE) Begin
   736            Move sDataVal to sDescVal
   737        End
   738        Else If (eMode=CB_CODE_DISPLAY_BOTH) Begin
   739            Move (sDataVal * "-" * sDescVal) to sDescVal
   740        End
   741        // else if deisplay description, juyst return the description as is
   742        Function_Return sDescVal
   743    End_Function // Column_Combo_Description_Value
   744
   745     
   746    // add an item to the combo 
   747    { Visibility=Private }
   748    Procedure ComboAddValidationTableItem String sDescription String sData
   749        Integer iItem
   750        tGridComboHelper GridComboHelper
   751
   752        Get pGridComboHelper to GridComboHelper
   753        Move (SizeOfArray(GridComboHelper.sDataValues)) to iItem
   754
   755        // this lets us convert the description. By default it returns the value passed.
   756        // This allows you to pass a data param that gets changed for display purposes.
   757        Get ComboDescriptionValue GridComboHelper.eCodeDisplay sDescription sData to sDescription
   758
   759        Send ComboAddItem sDescription iItem
   760
   761        Move sData to GridComboHelper.sDataValues[iItem]                 // the actual data value
   762
   763        // If description does not match the data we set this flag false
   764        If (sDescription<>sData and GridComboHelper.bDataOnly ) Begin
   765            Move False to GridComboHelper.bDataOnly
   766        End
   767        Set pGridComboHelper to GridComboHelper
   768    End_Procedure
   769
   770    // this is the one the callback calls. Passed info is predefined. We only need some of it
   771    { Visibility=Private }
   772    Procedure ComboFillItem Integer iItem String sData String sDescription Integer iFile RowID riId
   773        If (sDescription='') Begin
   774            Move sData to sDescription
   775        End
   776        Send ComboAddValidationTableItem sDescription sData
   777    End_Procedure
   778
   779    // adds a blank description
   780    { Visibility=Private }
   781    Procedure ComboAddBlankItem String sBlankDesc
   782        tGridComboHelper GridComboHelper
   783        Get pGridComboHelper to GridComboHelper
   784        Send ComboFillItem (SizeOfArray(GridComboHelper.sDataValues)) '' sBlankDesc 0 (NullRowId())
   785    End_Procedure
   786
   787    // Fills the list by loading the entire defined data-file
   788    { MethodType=Event }
   789    { Visibility=Private}
   790    Procedure ComboFillList
   791        Integer iFile iField eDisplayMode
   792        Handle  hoSrvr hoTable
   793        Boolean bEntry bAllowBlank
   794
   795        Send ComboDeleteData
   796
   797        Get Server to hoSrvr
   798        Get piBindingTable  to iFile
   799        Get piBindingColumn to iField
   800        If (hoSrvr and iFile) Begin
   801            Get ExecDDFileFieldStrFunction (RefFunc(File_Field_Table_Object)) to hoTable
   802            // this does a callback of ComboFillItem for each item in the list
   803            Send File_Field_Fill_List of hoSrvr iFile iField Self (RefProc(ComboFillItem))
   804            If hoTable Begin
   805                Get pbComboEntryState to bEntry
   806                Get Allow_Blank_State of hoTable to bAllowBlank
   807                If (not(bEntry) and bAllowBlank) Begin
   808                    Send ComboAddBlankItem DD_BLANK_CODE_DESCRIPTION
   809                End
   810            End
   811        End
   812    End_Procedure
   813    
   814    // augment to do the data to description translation if a combo
   815    { NoDoc=True }
   816    Function FormatDisplayValue String ByRef sValue Returns Boolean
   817        Boolean bCombo bAnsi
   818        Get pbComboButton to bCombo
   819        If bCombo Begin
   820            Get ComboDataToDescription sValue to sValue
   821        End
   822        Else Begin
   823            Forward Get FormatDisplayValue (&sValue) to bAnsi
   824        End
   825        Function_Return bAnsi
   826    End_Function
   827
   828    // augment to do the description to data translation if a combo
   829    { NoDoc=True }
   830    Function FormatEditedValue String sValue Returns String
   831        Boolean bCombo
   832        Get pbComboButton to bCombo
   833        If bCombo Begin
   834            Get ComboDescriptionToData sValue to sValue
   835        End
   836        Else Begin
   837            Forward Get FormatEditedValue sValue to sValue
   838        End
   839        Function_Return sValue
   840    End_Function
   841
   842    // a field options has changed. Update as needed
   843    { Visibility=Private }
   844    Procedure FileFieldOptionChanged Integer iFile Integer iField Integer iOptions Integer bClear
   845        Integer iTable iCol
   846        Boolean bPromptListBehavior
   847        Get pbPromptListBehavior to bPromptListBehavior
   848        Get piBindingTable to iTable
   849        Get piBindingColumn to iCol
   850        If (iTable=iFile and iCol=iField) Begin
   851            If (iOptions iand DD_NOENTER and (not(bPromptListBehavior))) Begin
   852                Set pbEditable to bClear  // if cleared, we allow entry
   853                Set pbFocusable to bClear
   854                Send DeferredRedraw
   855            End
   856            // Capslock
   857            If (iOptions iand DD_CAPSLOCK) Begin
   858                Set pbCapslock to (not(bClear))
   859                Send DeferredRedraw
   860            End
   861            If (iOptions iand DD_ZERO_SUPPRESS) Begin
   862                Send FileFieldMaskChanged iFile iField "" // does matter what mask we pass. It uses DD value
   863            End
   864        End
   865    End_Procedure
   866
   867    // DD mask has changed. Update as needed
   868    { Visibility=Private }
   869    Procedure FileFieldMaskChanged Integer iFile Integer iField String sMask
   870        Integer iTable iCol iOpts
   871        Handle hoDDO
   872        Get piBindingTable to iTable
   873        Get piBindingColumn to iCol
   874        If (iTable=iFile and iCol=iField) Begin
   875            Get Server to hoDDO
   876            Get File_field_Mask of hoDDO iFile iField to sMask
   877            If (sMask<>"") Begin
   878                Get File_Field_Options of hoDDO iFile iField to iOpts
   879                If (iOpts iand DD_ZERO_SUPPRESS) Begin
   880                    Move ("Z"+sMask) to sMask
   881                End
   882            End
   883            Set psMask to sMask
   884            Send DeferredRedraw
   885        End
   886    End_Procedure
   887
   888    // DD label has changed. If auto_label_state is T, then update any required labels
   889    { Visibility=Private }
   890    Procedure FileFieldLabelChanged Integer iFile Integer iField Boolean bLong String sLabel
   891        Boolean bAuto
   892        Integer iTable iCol
   893        String sName
   894        Handle hoDDO
   895        Get piBindingTable to iTable
   896        Get piBindingColumn to iCol
   897        Get Auto_Label_State to bAuto
   898        If (iTable=iFile and iCol=iField and bAuto) Begin
   899            Get Server to hoDDO
   900            Get File_Field_Label of hoDDO iFile iField DD_LABEL_SHORT to sName
   901            Set psCaption to sName
   902        End
   903    End_Procedure
   904
   905  // standard deo/dd augmentation to get status from DD
   906  { MethodType=Property NoDoc=True }
   907  Function Status_Help Returns String
   908      String sHelp
   909      Handle hoDD
   910      Integer iFile iField
   911      Forward Get Status_Help to sHelp
   912      If (sHelp="") Begin
   913         Get Server to hoDD
   914         Get piBindingTable to iFile
   915         Get piBindingColumn to iField
   916         If (hoDD and iFile) Begin
   917             Get File_Field_Status_Help of hoDD iFile iField to sHelp
   918         End
   919      End
   920      Function_Return sHelp
   921  End_Function
   922  
   923End_Class
   924
   925