Module Dfautmgn.pkg

     1//************************************************************************
     2// Confidential Trade Secret.
     3// Copyright (c) 1997 Data Access Corporation, Miami Florida
     4// as an unpublished work.  All rights reserved.
     5// DataFlex is a registered trademark of Data Access Corporation.
     6//
     7//****************************************************************************//
     8//                                                                            //
     9// $File name  : DFAutMgn.pkg - Mixin to assign auto margins and types        //
    10// $Author(s)  : John Tuohy                                                   //
    11//                                                                            //
    12// $Rev History                                                               //
    13// JT 10/14/97   Added better mask support. If datatype is a mask, do not     //
    14//               change it - assume it was explicitly set.                     //
    15// JT ??/??/??   File created                                                 //
    16//****************************************************************************//
    17// mixin class for automatically setting up form_margins, form_datatypes
    18// and form_column.
    19//
    20// Interface
    21//
    22//
    23//
    24//  Send Define_Form_Margins  - set form_margin and form_datatype for all
    25//                              items whose current form_margin is not 0.
    26//                              Numerics are all set as 0 (no decimal points)
    27//                              You must SET Points to set the decimal points.
    28//                              When we can get this information directly this
    29//                              will change. Sent by End_construct_Object
    30//
    31//  Send Define_Form_Margin Integer Item#
    32//                              Called by Define_form_Margins. As above
    33//
    34//  Send Define_List_Form_Columns
    35//                              Sets form_column for all items in a list
    36//                              whose current form_column value is zero.
    37//                              Sent by End_Construct_Object
    38//
    39//  Set Points {Item item#} to ##
    40//                              Sets decimal and adjust form_margin to
    41//                              accomodate the decimal point. Must be sent
    42//                              by program. If no item is passed 0 is used.
    43//
    44//
    45// Note: none of these should have any effect on existing programs. If
    46//       form_margin or form_column is already set (non-zero) these messages
    47//       will do nothing.
    48//
    49Use VDFBase.pkg
    50
    51Class Auto_Setup_Mixin is a Mixin
    52
    53   // Must be manually set because we can not get at this data
    54
    55   { MethodType=Property Visibility=Private }
    56   Procedure Set Points integer item# integer pos
    57     integer itm ps pobjid file# field# datatype margin len
    58
    59     if num_arguments eq 1 ;
    60        Move Item# to ps // itm will be 0
    61     else begin
    62        Move item# to itm
    63        Move pos   to ps
    64     end
    65     Get protoType_object to pObjId
    66     Get Data_File  of pObjID item Itm to File#
    67     Get Data_Field of pObjID item Itm to Field#
    68     if ps eq -1 ; // -1 = set to the default
    69        Get_Attribute DF_Field_Precision of file# field# to ps
    70
    71     Set Form_DataType item itm to ps
    72
    73     // set form margin
    74     If File# Begin
    75        Get_Attribute DF_Field_Length of file# field# to len
    76        If Ps Increment len
    77        Set Form_margin item itm to len
    78     End
    79   end_Procedure
    80
    81   //  set all form_columns settings for any form which is currently 0.
    82   //
    83   { Visibility=Private }
    84   Procedure Define_List_Form_Columns
    85     integer Item# Cnt prev_col col wd
    86
    87     Get Item_count of (ProtoType_object(Self)) to Cnt
    88     If Cnt gt 1 Begin
    89        Decrement Cnt                      // don't set first item
    90        Get Form_Column item 0 to Prev_col // 0 is already ok.
    91        For item# from 1 to cnt
    92           Get form_Column item item# to col
    93           If col eq 0 Begin
    94              Move (Form_Width(Self,item#-1)+Prev_Col) to col
    95              Set Form_Column item item# to col
    96           end
    97           Move col to Prev_col
    98        Loop
    99     end
   100   End_Procedure
   101
   102   { Visibility=Private }
   103   Procedure Define_Form_Margins
   104     integer Item# Cnt
   105     Get Item_count of (ProtoType_object(Self)) to Cnt
   106     Decrement Cnt
   107     For item# from 0 to cnt
   108         If (Form_margin(Self,item#)=0) ;
   109            send define_Form_Margin item#
   110     Loop
   111   End_Procedure
   112
   113   { Visibility=Private }
   114   Procedure Define_Form_Margin Integer item#
   115     integer pObjId file# Field#
   116     integer datatype margin wintype formtype
   117     Get protoType_object to pObjId
   118     Get Data_File  of pObjID item Item# to File#
   119     If File# Begin
   120        Get Data_Field of pObjID item Item# to Field#
   121        Get_Attribute DF_Field_Length of file# field# to Margin
   122        Get_Attribute DF_Field_Type of file# field#   to datatype
   123        move ASCII_WINDOW to wintype
   124        If (datatype=DF_BCD) Begin
   125           Get_Attribute DF_Field_Precision of file# field# to Wintype
   126           If WinType increment margin
   127        end
   128        Else If (datatype=DF_DATE) Begin
   129           move DATE_WINDOW to wintype
   130           move 10 to margin
   131        end
   132        Else If (datatype=DF_DATETIME) Begin
   133           // if someone is using datetime, it is best that they use a mask. If nothing
   134           // is provided, we will use an ascii window. DEOs will change this to mask_datetime_window but
   135           // not DEOs will not. Don't set datetime mask here because there would be no way for the
   136           // DD logic to figure out if the type was changed in the Deo object. The DD Deosassume that
   137           // datetime /w ascii_window is the unassigned value and that it is safe to chane it.
   138           Move Ascii_Window to wintype // if no mask set, we will just use non-maks ascii window
   139           Move 26 to margin // should be enough for "mm/dd/yyyy hh:mm:ss.fff pm"
   140        End
   141        Set Form_Margin   item Item# to Margin
   142        Get Form_datatype item item# to Formtype
   143        If ( (Formtype=MASK_NUMERIC_WINDOW OR ;
   144              FormType=MASK_CURRENCY_WINDOW) AND ;
   145              Form_Mask(Self,item#)='') Begin
   146                 If WinType gt 0 Subtract (WinType+1) from Margin
   147                 If Formtype eq MASK_CURRENCY_WINDOW ;
   148                    Set Currency_Mask item Item# to Margin wintype
   149                  Else ;
   150                    Set Numeric_Mask item Item# to Margin wintype
   151        End
   152        Else If FormType le ascii_window ; // only auto-set if non mask. If type is a mask
   153           Set Form_DataType Item Item# to wintype // we assume it was defined.
   154     End
   155     Else ;
   156        Set Form_Margin   item Item# to (form_width(Self,Item#))
   157   End_Procedure
   158
   159end_class
   160