skip to main content
OpenEdge Development: AppBuilder
Multiple Layouts : How multiple layouts work: a look at the code
 
How multiple layouts work: a look at the code
Within a procedure file, the AppBuilder supports an alternate layout with the following code:
*Run‑time Properties and AppBuilder Settings code section.
*Layout cases ({&LAYOUT-VARIABLE} variables) internal procedure.
*Enable_UI internal procedure.
Run-time properties and AppBuilder settings
For each alternate layout, the AppBuilder places an IF statement in the Run‑time Properties and AppBuilder Settings code section. This IF statement checks to see whether the layout’s run‑time expression evaluates to TRUE. If so, this statement runs the layout case’s internal procedure, passing to it the name of the layout as an input parameter.
For example, the multi‑layout run‑time adjustments code appears as follows:
 
/* _MULTI-LAYOUT-RUN-TIME-ADJUSTMENTS */
 
/* LAYOUT-NAME: "Standard Character"
   LAYOUT-TYPE: CHARACTER
   EXPRESSION:  SESSION:DISPLAY-TYPE = ’TTY’:U 
   COMMENT:     This layout is the standard layout specification for
                 a customized Character based terminal. It is usually
                 selected to modify a window that has a GUI based
                 master layout.
                                                                        */
IF SESSION:DISPLAY-TYPE = ’TTY’:U THEN 
  RUN C-Win-layouts (INPUT ’Standard Character’:U) NO-ERROR.
 
/* LAYOUT-NAME: "Standard MS Windows"
   LAYOUT-TYPE: GUI
   EXPRESSION:  SESSION:WINDOW-SYSTEM = ’Windows’:U 
   COMMENT:     This layout is the standard layout specification for
                 a customized MS Windows window. It is usually
                 selected to modify a window that needs to have a
                 standard "MS Windows" look.
                                                                        */
ELSE IF SESSION:WINDOW-SYSTEM = ’Windows’:U THEN 
  RUN C-Win-layouts (INPUT ’Standard MS Windows’:U) NO-ERROR.
 
/* LAYOUT-NAME: "Standard Windows 95"
   LAYOUT-TYPE: GUI
   EXPRESSION:  SESSION:WINDOW-SYSTEM = ’MS-WIN95’:U
   COMMENT:     This layout is the standard layout specification for
                 a customized Windows 95 window. It is usually
                 selected to modify a window that needs to have a
                 standard "Windows 95" look.
                                                                        */
ELSE IF SESSION:WINDOW-SYSTEM = ’MS-WIN95’:U THEN 
  RUN C-Win-layouts (INPUT ’Standard Windows 95’:U) NO-ERROR.
 
/* END-OF-LAYOUT-DEFINITIONS */
 
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win) THEN 
  C-Win:HIDDEN = no.
If the expression SESSION:WINDOW-SYSTEM = ’Windows’:U evaluates to TRUE, this IF statement passes the input parameter ’Standard MS Windows’ to the layout cases internal procedure. For SmartObjects, the DefaultLayout property is set. This is used to run the appropriate layout case later, when the SmartObject is initialized.
Thus, for SmartObjects, the multi‑layout run‑time adjustments code appears as follows:
 
/* _MULTI-LAYOUT-RUN-TIME-ADJUSTMENTS */
 
/* LAYOUT-NAME: "Standard Character"
   LAYOUT-TYPE: CHARACTER
   EXPRESSION:  SESSION:DISPLAY-TYPE = ’TTY’:U 
   COMMENT:     This layout is the standard layout specification for
                 a customized Character based terminal. It is usually
                 selected to modify a window that has a GUI based
                 master layout.
                                                                        */
IF SESSION:DISPLAY-TYPE = ’TTY’:U THEN 
  DYNAMIC-FUNCTION(’setDefaultLayout’:U, ’Standard Character’:U) NO-ERROR.
 
/* LAYOUT-NAME: "Standard MS Windows"
   LAYOUT-TYPE: GUI
   EXPRESSION:  SESSION:WINDOW-SYSTEM = ’Windows’:U 
   COMMENT:     This layout is the standard layout specification for
                 a customized MS Windows window. It is usually
                 selected to modify a window that needs to have a
                 standard "MS Windows" look.
                                                                        */
ELSE IF SESSION:WINDOW-SYSTEM = ’Windows’:U THEN 
  DYNAMIC-FUNCTION(’setDefaultLayout’:U, ’Standard MS Windows’:U) NO-ERROR.
 
/* LAYOUT-NAME: "Standard Windows 95"
   LAYOUT-TYPE: GUI
   EXPRESSION:  SESSION:WINDOW-SYSTEM = ’MS-WIN95’:U
   COMMENT:     This layout is the standard layout specification for
                 a customized Windows 95 window. It is usually
                 selected to modify a window that needs to have a
                 standard "Windows 95" look.
                                                                        */
ELSE IF SESSION:WINDOW-SYSTEM = ’MS-WIN95’:U THEN 
  DYNAMIC-FUNCTION(’setDefaultLayout’:U, ’Standard Windows 95’:U) NO-ERROR.
 
DYNAMIC-FUNCTION(’setLayoutOptions’:U, "Master Layout,Standard Character,Standard MS Windows,Standard Windows 95":U).
Layout cases internal procedure
This internal procedure contains a CASE statement that has an entry for each layout in the procedure file. The CASE statement entry contains the run‑time assignments for the layout. The Preprocessor reference {&LAYOUT-VARIABLE} resolves to the name of the window in the procedure file prefixed to -layout. Following is a sample layout case’s internal procedure. Note that the variable name {&LAYOUT-VARIABLE} is usually the same as {&WINDOW-NAME}-layout. The layout cases internal procedure is named {&LAYOUT-VARIABLE} variables, which in this sample resolves to C-Win-layouts:
 
Example 3: Layout cases internal procedure 
PROCEDURE C-Win-layouts:
  DEFINE INPUT PARAMETER layout AS CHARACTER NO-UNDO.
 
  DEFINE VARIABLE lbl-hndl AS HANDLE         NO-UNDO.
  DEFINE VARIABLE widg-pos AS DECIMAL        NO-UNDO.
 
  /* Copy the name of the active layout into a variable accessible to the rest
     of this file. */
  C-Win-layout = layout.
 
  CASE layout:
    WHEN "Master Layout" THEN DO:
      ASSIGN
         &IF ’{&WINDOW-SYSTEM}’ NE ’TTY’:U &THEN
         C-Win:HIDDEN                                     = yes &ENDIF
         C-Win:HEIGHT                                     = 16.
 
      ASSIGN
         Btn_Done:HIDDEN IN FRAME DEFAULT-FRAME           = yes
         Btn_Done:HEIGHT IN FRAME DEFAULT-FRAME           = 1.14
         Btn_Done:ROW IN FRAME DEFAULT-FRAME              = 3.62
         Btn_Done:HIDDEN IN FRAME DEFAULT-FRAME           = no.
 
      ASSIGN
         Btn_Help:HIDDEN IN FRAME DEFAULT-FRAME           = yes
         Btn_Help:HEIGHT IN FRAME DEFAULT-FRAME           = 1.14
         Btn_Help:ROW IN FRAME DEFAULT-FRAME              = 3.38
         Btn_Help:HIDDEN IN FRAME DEFAULT-FRAME           = no
         Btn_Help:HIDDEN IN FRAME DEFAULT-FRAME           = no.
      ASSIGN
         C-Win:VIRTUAL-HEIGHT                             = 16.00
         &IF ’{&WINDOW-SYSTEM}’ NE ’TTY’:U &THEN
         C-Win:HIDDEN                                     = no &ENDIF.
    END. /* Master Layout Layout Case */
 
    WHEN "Standard Character":U THEN DO:
      ASSIGN
         Btn_Done:HIDDEN IN FRAME DEFAULT-FRAME           = yes
         Btn_Done:HEIGHT IN FRAME DEFAULT-FRAME           = 1
         Btn_Done:ROW IN FRAME DEFAULT-FRAME              = 4
         Btn_Done:HIDDEN IN FRAME DEFAULT-FRAME           = no NO-ERROR.
 
      ASSIGN
         Btn_Help:HIDDEN IN FRAME DEFAULT-FRAME           = yes
         Btn_Help:HEIGHT IN FRAME DEFAULT-FRAME           = 1
         Btn_Help:ROW IN FRAME DEFAULT-FRAME              = 3 NO-ERROR.
 
    END. /* Standard Character Layout Case */
  END CASE.
END PROCEDURE. /* C-Win-layouts */
This sample contains CASE statement entries for two layouts, the master layout and the standard character layout. The Btn_Help button appears in the master layout but not in the standard character layout. The master layout also sets size properties to decimal character units because a graphical environment supports fractions of a character. However, in a character environment, they are set to integer character units.
Enable_UI internal procedure
The Enable_UI internal procedure controls whether widgets are enabled for specific layouts. This procedure is used only for non‑SmartObject procedure files. It uses the WHEN option of the ENABLE statement to determine whether a widget in a SmartObject is enabled.
The following is a sample Enable_UI procedure:
 
PROCEDURE enable_UI :
/*------------------------------------------------------------------------
  Purpose:     ENABLE the User Interface
  Parameters:  <none>
  Notes:       Here we display/view/enable the widgets in the
               user-interface. In addition, OPEN all queries
               associated with each FRAME and BROWSE.
               These statements here are based on the "Other 
               Settings" section of the widget Property Sheets.
------------------------------------------------------------------------*/
 
  {&OPEN-QUERY-DEFAULT-FRAME}
  GET FIRST DEFAULT-FRAME.
  IF AVAILABLE Customer THEN 
    DISPLAY Customer.Cust-Num Customer.Name 
      WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
  ENABLE IMAGE-1 Btn_First Btn_Next Btn_Prev Btn_Last BROWSE-1 
         Btn_Photo WHEN NOT (SESSION:DISPLAY-TYPE = ’TTY’:U ) 
      WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
  {&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME}
  VIEW C-Win.
END PROCEDURE.
In this example, the Btn_Photo is enabled only if the standard character layout is not used at run time.