%StandardWindowHandling #GROUP 

Top  Previous  Next

This #GROUP generates all the code to handle field-independent events for the procedure. It generates its code inside the Window template's CASE EVENT() structure.

#GROUP(%StandardWindowHandling)

#FOR(%WindowEvent)

 #SUSPEND

#?OF EVENT:%WindowEvent

 #EMBED(%WindowEventHandling,'Window Event Handling'),%WindowEvent

 #CASE(%WindowEvent)

 #OF('OpenWindow')

 IF NOT WindowInitialized

   DO InitializeWindow

   WindowInitialized = True

 END

   #IF(%FirstField)

 SELECT(%FirstField)

   #ENDIF

 #OF('GainFocus')

 ForceRefresh = True

 IF NOT WindowInitialized

   DO InitializeWindow

   WindowInitialized = True

 ELSE

   DO RefreshWindow

 END

 #OF('Sized')

 ForceRefresh = True

 DO RefreshWindow

 #ENDCASE

 #EMBED(%PostWindowEventHandling,'Window Event Handling, after generated code') %|

        ,%WindowEvent

 #RESUME

#ENDFOR

OF Event:Rejected

 #EMBED(%WindowEventHandlingBeforeRejected,'Window Event Handling - Before Rejected')

 BEEP

 DISPLAY(?)

 SELECT(?)

 #EMBED(%WindowEventHandlingAfterRejected,'Window Event Handling - After Rejected')

#SUSPEND

#?ELSE

 #EMBED(%WindowOtherEventHandling,'Other Window Event Handling')

#RESUME

 

This #GROUP starts with #FOR(%WindowEvent). This means it will loop through every instance of the %WindowEvent symbol, generating code (if required) for each field-independent event in the procedure.

The #SUSPEND statement begins the section of code that will only conditionally generate code if an explicit code statement (without #?) generates, or if the programmer has placed some embedded source or used a Code or Extension template to generate code into an embed point.

The #?OF EVENT:%WindowEvent statement conditionally generates an OF clause to the CASE EVENT() structure for the currently processing instance of %WindowEvent. This line of code, since it is prefaced with #?, will only generate if there is some other code generated within it, eliminating an empty OF clause.

The #EMBED statement is the key to the source generation process, and to the Procedure template's interaction with Code, Control, and Extension templates. Because it has the ",%WindowEvent" appended to the end, the programmer will have a separate embed point available for every instance of the %WindowEvent symbol. This means programmers can write their own code for any field-independent event . It also means any Code, Ccontrol, or Eextension templates the programmer places in the procedure can generate code into these embed points, as needed, to produce the code necessary to support their functionality. These embed points are the targets of the #AT statements used in the Code, Control, and Extension templates.

The #CASE(%WindowEvent) structure generates explicit source code for the field-independent events in its structure. The #OF('OpenWindow') checks for EVENT:OpenWindow and generates the check on the WindowInitialized variable to conditionally initialize the windowand set WindowInitialized to true. This code executes if no EVENT:GainFocus has already occurred (such as opening a second window on the same execution thread that currently has focus). The SELECT(%FirstField) statement is generated only if there are any controls that can receive focus in the window.

The #OF('GainFocus') statement checks for EVENT:GainFocus and generates the ForceRefresh = True, then checks to see if the window has already been initialized (if the user is switching between active threads it would have been). If not, it initializes the window, otherwise it simply refreshes it. The #OF('Sized') statement checks for EVENT:Sized and generates ForceRefresh = True and DO RefreshWindow to refresh the window after the user has resized it.

The #ENDCASE statement terminates the #CASE structure. The next #EMBED allows the programmer an opportunity to embed their own code following the generated code for any of these events. The #RESUME statement terminates the #SUSPEND section. If no source code has actually been generated, no conditional source statements (prefaced by #?) between the #SUSPEND and the #RESUME are generated.

#ENDFOR terminates the #FOR loop, then OF EVENT:Rejected generates and offers before and after embed points surrounding standard code to alert the user that the data input into the current control has been rejected (usually the data is out of range) and leave them on the same control.

The #SUSPEND statement begins another conditional generation section. This means the #?ELSE statement only generates an ELSE if source code is generated by the #EMBED statement. #RESUME terminates this #SUSPEND section.