home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / dataflex / list.pkg < prev    next >
Encoding:
Text File  |  1993-08-10  |  13.6 KB  |  449 lines

  1. //************************************************************************
  2. //
  3. // Copyright 1987-1992 Data Access Corporation, Miami FL, USA
  4. // All Rights reserved
  5. // DataFlex is a registered trademark of Data Access Corporation.
  6. //
  7. //
  8. //     $Source: /u3/source.30/product/pkg/RCS/list.pkg,v $
  9. //     $Revision: 1.1 $
  10. //     $State: Exp $
  11. //     $Author: james $
  12. //     $Date: 1992/09/08 14:43:07 $
  13. //     $Locker:  $
  14. //
  15. //     $Log: list.pkg,v $
  16. //Revision 1.1  1992/09/08  14:43:07  james
  17. //Initial revision
  18. //
  19. //Revision 1.9  92/06/06  01:57:36  lee
  20. //added register_procedure move_value_out
  21. //
  22. //Revision 1.8  92/05/29  14:06:13  lee
  23. //removed end_construct_* messages from mixins; now, classes that use the mixin
  24. //send the message that used to be sent by the end_construct_* message (for
  25. //efficiency).
  26. //
  27. //Revision 1.7  92/05/14  15:53:34  unknown
  28. //Updated Copyright slug - SWM.
  29. //
  30. //Revision 1.6  92/04/01  00:33:32  lee
  31. //removed navstart and liststart (unused), renamed bind_main_file and bind_index
  32. //in datalist to bind_list_main_file and bind_list_index to avoid conflict with
  33. //commands used by data_set, moved bind_static from sellist to datalist as it
  34. //only sets properties defined in datalist (not sellist).
  35. //
  36. //Revision 1.5  92/03/29  18:45:01  lee
  37. //added MSG_END_CONSTRUCT_OBJECT, moved ENDMAC macro stuff into END_CONSTRUCT-
  38. //OBJECT procedures (in .pkgs). moved Flag_ITems to list.pkg after generalizing
  39. //it based on PROTOTYPE_OBJECT instead of Whether or not it is a table-oriented
  40. //object. Moved define_access_keys mechanism completely into actionbr.pkg.
  41. //fixed two typos: import_class_protocol used !# instead of !3, and register-
  42. //procedure used !1 instead of !2.
  43. //
  44. //Revision 1.4  92/03/09  19:03:16  james
  45. //Added #CHKSUB directive to insure source
  46. //only compiled with correct revision of 
  47. //compiler.
  48. //
  49. //Revision 1.3  92/02/12  17:46:53  steve-l
  50. //Bind_Target corrected - was skipping arg !2 on recursion
  51. //
  52. //Revision 1.2  91/11/08  09:23:28  steve-l
  53. //it
  54. //
  55. //************************************************************************/
  56.  
  57. //************************************************************************
  58. //     File Name: List.Pkg
  59. // Creation Date: January 1, 1991
  60. // Modified Date: Feb 12, 1992
  61. //     Author(s): Steven A. Lowe
  62. //
  63. // This module defines the properties and operations required to support
  64. // list-selection, collected in the abstract class List_Mixin.
  65. //
  66. // This file should be USEd prior to and IMPORTed within the scope of the
  67. // class definition by any user-interface (esp. data-entry) class which
  68. // must support the data-entry object standards.
  69. //
  70. // This file is used by PICKLIST.PKG and SELLIST.PKG.
  71. //************************************************************************/
  72.  
  73. #CHKSUB 1 1 // Verify the UI subsystem.
  74.  
  75. use ui
  76.  
  77. register_procedure move_value_out
  78.  
  79. class list_mixin is a message
  80.  
  81.   //
  82.   // Description
  83.   //
  84.   //   This procedure defines the accelerator keys and properties required
  85.   //   to support the standard list-selection options.
  86.   //
  87.   // Assumptions/Preconditions
  88.   //
  89.   //   This procedure should only be invoked from within the Construct_Object
  90.   //   procedure of a class.
  91.   //
  92.   // Exceptions
  93.   //
  94.   //   None.
  95.   //
  96.   // Notes
  97.   //
  98.   //   Enumeration_Counter is used to scan selected items.
  99.   //  
  100.   //   Export_Item_State determines if the value of the selected item in a
  101.   //   single-select or auto-select list should be placed into the current
  102.   //   item of the object which 'invoked' the list (i.e. the object which
  103.   //   had the focus when this object was activated - see Invoking_Object_ID).
  104.   //
  105.   //   Invoking_Object_ID is the object id of the object which had the focus
  106.   //   when this object was activated.
  107.   //
  108.   //   Original_Selection is the item# (if batch) or record number (if virtual)
  109.   //   of the item which was selected when the list was activated.
  110.   //
  111.   //   Radio_State determines if the items in this list are radio-buttons.
  112.   //
  113.   //   Target_Field identifies the field (in the Target_File), if any, which
  114.   //   should receive the value of the currently selected item during a save
  115.   //   operation (i.e. when the Entry_Update message is received during a
  116.   //   save operation).  This only applies to single-select or auto-select
  117.   //   lists, not multi-select or no-select lists.
  118.   //
  119.   //   Target_File identifies the file, if any, which has a field that should
  120.   //   receive the value of the currently selected item during a save operation
  121.   //   (see Target_Field).
  122.   //
  123.   procedure define_list
  124.     set select_mode to SINGLE_SELECT
  125.     set search_mode to INCREMENTAL
  126.     on_key kCancel SEND CANCEL           PRIVATE
  127.     on_key kEnter  SEND OK               PRIVATE
  128.     on_key kSpace  SEND Toggle_Select    PRIVATE
  129.     Property integer Enumeration_Counter PUBLIC  0
  130.     Property integer Export_Item_State   PUBLIC  0
  131.     Property integer Invoking_Object_ID  PUBLIC  0
  132.     Property integer Original_Selection  PUBLIC  0
  133.     Property integer Radio_State         PUBLIC  0
  134.     Property integer Target_Field        PUBLIC  0
  135.     Property integer Target_File         PUBLIC  0
  136.   end_procedure
  137.  
  138.  
  139.   //
  140.   // Description
  141.   //
  142.   //   This procedure records the identity of the object which has the focus
  143.   //   prior to the normal activation of this object (sets Invoking_Object_ID
  144.   //   if activation succeeds).  This procedure returns a non-zero value if
  145.   //   the activation failed.
  146.   //
  147.   // Assumptions/Preconditions
  148.   //
  149.   //   This object (or one of its ancestor classes) understands the Activating
  150.   //   message.
  151.   //
  152.   // Exceptions
  153.   //
  154.   //   None.
  155.   //
  156.   // Notes
  157.   //
  158.   //   None.
  159.   //
  160.   procedure activating returns integer
  161.     local integer pScope item# dirt
  162.     local string val
  163.     get focus of desktop to pscope
  164.     forward get MSG_activating to dirt
  165.     if dirt ne 0 procedure_return dirt
  166.     if (pscope <> 0 AND pscope <> DESKTOP) ;
  167.         set Invoking_Object_ID to pScope
  168.   end_procedure
  169.  
  170.  
  171.   //
  172.   // Description
  173.   //
  174.   //   This procedure resets Block_Mouse_State and Scope_State for this object
  175.   //   after a successful deactivation if this object is a pop-up object.
  176.   //   This procedure returns a non-zero value if the deactivation failed.
  177.   //
  178.   // Assumptions/Preconditions
  179.   //
  180.   //   This object (or one of its ancestor classes) understands the
  181.   //   Deactivating message, and has the (boolean) properties Popup_State and
  182.   //   Block_Mouse_State.
  183.   //
  184.   // Exceptions
  185.   //
  186.   //   None.
  187.   //
  188.   // Notes
  189.   //
  190.   //   Reverses the side-effects of the PopUp procedure (see below).
  191.   //
  192.   procedure deactivating returns integer
  193.     local integer dirt
  194.     forward get MSG_deactivating to dirt
  195.     if dirt ne 0 procedure_return dirt
  196.     if (Popup_State(current_object)) begin
  197.       set Block_Mouse_State to false
  198.       set Scope_State to FALSE
  199.     end
  200.   end_procedure
  201.  
  202.  
  203.   //
  204.   // Description
  205.   //
  206.   //   This procedure sets the Block_Mouse_State and Scope_State properties
  207.   //   of this object to TRUE prior to the normal pop-up activation operation,
  208.   //   if and only if the PopUp_State of this object is TRUE.  This is done to
  209.   //   ensure that pop-up list objects are scoped (to prevent the entry- and
  210.   //   exit-messages of items from being executed) and that the mouse is
  211.   //   prevented from clicking anywhere outside of this list object.
  212.   //
  213.   // Assumptions/Preconditions
  214.   //
  215.   //   This object (or one of its ancestor classes) understands the
  216.   //   PopUp message, and has the (boolean) properties Popup_State and
  217.   //   Block_Mouse_State.
  218.   //
  219.   // Exceptions
  220.   //
  221.   //   None.
  222.   //
  223.   // Notes
  224.   //
  225.   //   The Deactivating procedure reverses the side-effects of this procedure.
  226.   //
  227.   procedure popup
  228.     if (Popup_State(current_object)) begin
  229.       set Block_Mouse_state to true
  230.       set scope_state to true
  231.     end
  232.     forward send popup
  233.   end_procedure
  234.  
  235.  
  236.   //
  237.   // Description
  238.   //
  239.   //   This procedure inserts a new item into the list before the specified
  240.   //   item#, using the specified message id (msg#) and value.
  241.   //
  242.   //   It ensures that the Entry_State of the new item is FALSE, and that
  243.   //   the Checkbox_Item_State of the new item is TRUE if this object's
  244.   //   Radio_State is TRUE.
  245.   //
  246.   // Assumptions/Preconditions
  247.   //
  248.   //   msg# should be a valid message id or 0.
  249.   //   item# should be a valid item index (between 0 and Item_Count-1).
  250.   //
  251.   // Exceptions
  252.   //
  253.   //   None.
  254.   //
  255.   // Notes
  256.   //
  257.   //   After successful execution, the item index of the new item is the same
  258.   //   as the originally specified item#.
  259.   //
  260.   procedure insert_item integer msg# string value integer item#
  261.     forward send insert_item msg# value item#
  262.     set entry_state item item# to false
  263.     if (Radio_State(current_object)) ;
  264.         set Checkbox_Item_State item item# to true
  265.   end_procedure
  266.  
  267.  
  268.   //
  269.   // Description
  270.   //
  271.   //   This procedure adds a new item at the end of the list, using the
  272.   //   specified message id (msg#) and value.
  273.   //
  274.   //   It ensures that the Entry_State of the new item is FALSE, and that
  275.   //   the Checkbox_Item_State of the new item is TRUE if this object's
  276.   //   Radio_State is TRUE.
  277.   //
  278.   // Assumptions/Preconditions
  279.   //
  280.   //   msg# should be a valid message id or 0.
  281.   //
  282.   // Exceptions
  283.   //
  284.   //   None.
  285.   //
  286.   // Notes
  287.   //
  288.   //   After successful execution, the item index of the new item is
  289.   //   Item_Count-1.
  290.   //
  291.   procedure add_item integer msg# string value
  292.     local integer item#
  293.     forward send add_item msg# value
  294.     calc (item_count(current_object) - 1) to item#
  295.     set entry_state item item# to false
  296.     if (Radio_State(current_object)) ;
  297.         set Checkbox_Item_State item item# to true
  298.   end_procedure
  299.  
  300.  
  301.   //
  302.   // Description
  303.   //
  304.   //   This procedure accepts the selected item(s) in the list, and surrenders
  305.   //   the focus.
  306.   //
  307.   //   The incremental-search index is reset.
  308.   //
  309.   //   The value of the current item may be exported to the current item of the
  310.   //   invoking object, and this object deactivated, if this object is a pop-up,
  311.   //   or the focus may be given to the next object in the rotation order.
  312.   //
  313.   // Assumptions/Preconditions
  314.   //
  315.   //   This object (or one or its ancestor classes) must understand the
  316.   //   Move_Value_Out message as a method of exporting a value, the
  317.   //   Request_Cancel message as a method of deactivating this object, and
  318.   //   the Next message as a method of rotating to the next focusable object.
  319.   //
  320.   // Exceptions
  321.   //
  322.   //   None.
  323.   //
  324.   // Notes
  325.   //
  326.   //   Sent by kENTER.
  327.   //
  328.   procedure OK returns integer
  329.     local integer selMode
  330.     set search_mode to (search_mode(current_object))  //reset incr srch index
  331.     if (popup_state(current_object)) begin
  332.       get select_mode to selMode
  333.       set select_state item CURRENT to true
  334.       if ((SelMode = SINGLE_SELECT OR SelMode = AUTO_SELECT) AND ;
  335.           Select_Count(current_object) > 0) send move_value_out
  336.       else set Enumeration_Counter to 0  //multi-select or none selected
  337.       send request_cancel
  338.     end
  339.     else send NEXT
  340.   end_procedure
  341.  
  342.   //
  343.   // Description
  344.   //
  345.   //   This procedure toggles the select_state of the current item unless the
  346.   //   select-mode of this object is no_select, in which case this procedure
  347.   //   mimics the pressing of the space-bar to generate a space character for
  348.   //   incremental search.
  349.   //
  350.   // Assumptions/Preconditions
  351.   //
  352.   //   This object must understand the Key message as a method of character
  353.   //   input, and must also understand the Select_Toggling message as a method
  354.   //   of altering the select_state of an item.
  355.   //
  356.   // Exceptions
  357.   //
  358.   //   None.
  359.   //
  360.   // Notes
  361.   //
  362.   //   Sent by kSpace.
  363.   //
  364.   procedure toggle_select
  365.     if (select_mode(current_object) = NO_SELECT) send key kSpace
  366.     else send select_toggling CURRENT TOGGLE_STATE
  367.   end_procedure
  368.  
  369.   procedure Flag_Items
  370.     local integer count maxx radState obj#
  371.     move (Prototype_Object(current_object)) to obj#
  372.     calc (Item_Count(obj#) - 1) to maxx
  373.     get Radio_State to radState
  374.     for count from 0 to maxx
  375.       set Entry_State of obj# item count to false
  376.       if radState ne 0 set Checkbox_Item_State of obj# item count to true
  377.     loop
  378.   end_procedure
  379. end_class
  380.  
  381.  
  382. //
  383. // Description
  384. //
  385. //   This macro processes the argument to the FOR option of the listStart
  386. //   macro, if any.
  387. //
  388. //   Target_File and Target_Field are set according to the argument.
  389. //
  390. // Assumptions/Preconditions
  391. //
  392. //   The argument to the FOR option (if there is a FOR option in the
  393. //   command line arguments) must be a file.field identifier.
  394. //
  395. // Exceptions
  396. //
  397. //   None.
  398. //
  399. // Notes
  400. //
  401. //   None.
  402. //
  403. #COMMAND Bind_Target
  404.   #IF (!0>1)
  405.     #IFSAME !1 FOR
  406.       #PUSH !u
  407.       #SET U$ !2  //get file#
  408.       set Target_File to |CI!u
  409.       #SET U$ %!2 //get field#
  410.       set Target_Field to |CI!u
  411.       #POP U$
  412.     #ELSE
  413.       Bind_Target !2 !3 !4 !5 !6 !7 !8 !9
  414.     #ENDIF
  415.   #ENDIF
  416. #ENDCOMMAND
  417.  
  418.  
  419. //
  420. // Description
  421. //
  422. //   This macro processes the RADIO option of the listStart macro.
  423. //
  424. //   Radio_State is set to TRUE, and Select_Mode is set to auto-select
  425. //   if the RADIO option appears in the command line arguments.
  426. //
  427. // Assumptions/Preconditions
  428. //
  429. //   None.
  430. //
  431. // Exceptions
  432. //
  433. //   None.
  434. //
  435. // Notes
  436. //
  437. //   None.
  438. //
  439. #COMMAND Bind_Radio
  440.   #IF (!0>0)
  441.     #IFSAME !1 RADIO
  442.       set Radio_State to true
  443.       set select_mode to AUTO_SELECT
  444.     #ELSE
  445.       Bind_Radio !2 !3 !4 !5 !6 !7 !8 !9
  446.     #ENDIF
  447.   #ENDIF
  448. #ENDCOMMAND
  449.