Creating a start menu by means of the built-in 4gl functions

 

We wand to run upto 6 programs in mdi mode:

 

 

To run programs in mdi mode, we do the following:

set the start menu,

activate the mdi mode.

 

Step 1

Create a new project called My MDI project

 

Step 2

Create 7 programs:

startmenu_4glfunc   to serve as the mdi container

6 others   to be run in the mdi mode (create_menu(), menu_add_option(), menu_add_submenu(), menu_publish(), execute_menu(), and congratulations)

 

Step 3

Build and deploy child programs. Child program must be compiled and deployed to the application server before you run the main program. Child programs do not get deployed automatically.

 

Step 4

Build and run the main program. If everything was done properly, you will be able to run all the programs:

 

 

 

 

Please, note that you will be able to start the child programs specified in the source file but they will NOT be run in the mdi mode. Program "startmenu_4glfunc" does not activate the mdi mode.

 

Step 5

Activate the mdi mode by ui methods:

 

  CALL ui.Interface.setType("container")

  CALL ui.Application.GetCurrent().setMenuType("Menu")

  CALL ui.Interface.setName("My MDI Container")

  CALL ui.Interface.setText("Welcome to the MDI mode")

 

Step 6

Once it is activated, you will be able to run the child programs in the MDI mode

 

 

 

Here are the source codes and runtime appearance for the programs referenced above:

 

startmenu_4glfunc

 

MAIN

 

DEFINE

 main_menu_id INT,

 submenu1_id, submenu2_id, exit_id INT,

 action_id INT

 

CALL ui.Interface.setType("Container")

 

LET main_menu_id = create_menu()

 

LET submenu1_id = menu_add_submenu(main_menu_id, "start menu")

CALL menu_add_option(submenu1_id, "create_menu()",101)

CALL menu_add_option(submenu1_id, "menu_add_option()",102)

CALL menu_add_option(submenu1_id, "menu_add_submenu()",103)

CALL menu_add_option(submenu1_id, "menu_publish()",104)

CALL menu_add_option(submenu1_id, "execute_menu()",105)

 

LET submenu2_id = menu_add_submenu(main_menu_id, "feedback")

CALL menu_add_option(submenu2_id, "your feedback",201)

 

LET exit_id = menu_add_option(main_menu_id, "exit",301)

 

LET action_id = 0

 

WHILE TRUE

CALL menu_publish()

  LET action_id = execute_menu()

 

  IF action_id = 0 THEN

   CONTINUE WHILE

  END IF

  

 

  CASE action_id

  WHEN 101

     CALL exec_program("create_menu", "localhost", "default", "system")

  WHEN 102

     CALL exec_program("menu_add_option", "localhost", "default", "system")

  WHEN 103

    CALL exec_program("menu_add_submenu", "localhost", "default", "system")

  WHEN 104

    CALL exec_program("menu_publish", "localhost", "default", "system")

  WHEN 105

    CALL exec_program("execute_menu", "localhost", "default", "system")

  WHEN 201

    CALL exec_program("congratulations", "localhost", "default", "system")

  WHEN 301

    EXIT WHILE

  END CASE

 

END WHILE

 

END MAIN

 

create_menu

 

MAIN

 

  OPEN WINDOW a AT 1,1 WITH 15 ROWS, 60 COLUMNS

 

  DISPLAY "create_menu()" AT 2,2 ATTRIBUTE (BLUE, BOLD)

  DISPLAY "creates a ring menu;" AT 4,2

  DISPLAY "generates a menu_id (of INTEGER data type)" AT 5,2

  DISPLAY "used then adding options and submenus." AT 6,3

  DISPLAY "LET menu_id=create_menu()" AT 8,5 ATTRIBUTE (BLUE)

 

CALL fgl_getkey()

 

END MAIN

 

menu_add_option

 

MAIN

 

  OPEN WINDOW b AT 3,10 WITH 15 ROWS, 60 COLUMNS

 

  DISPLAY "menu_add_option()" AT 2,2 ATTRIBUTE (GREEN, BOLD)

  DISPLAY "create an option within a menu, " AT 4,2

  DISPLAY "created by the create_menu() function" AT 5,4

  DISPLAY "accepts four parameters:" AT 6,2

  DISPLAY "menu_id" AT 7,3 ATTRIBUTE (GREEN)

  DISPLAY " - refers to the menu ID generated by create_menu()" AT 7,10

  DISPLAY "label" AT 8,3 ATTRIBUTE (GREEN)

  DISPLAY " - specifies the name of the menu option" AT 8,10

  DISPLAY "action_id" AT 9,3 ATTRIBUTE (GREEN)

  DISPLAY " - specifies the action" AT 9,10

  DISPLAY "enabled" AT 10,3 ATTRIBUTE (GREEN)

  DISPLAY " - (optional) specifies whether" AT 10,10

  DISPLAY "the menu option should be visible or not" AT 11,8

  DISPLAY 'CALL menu_add_option(menu_id, "first option", action_id)' AT 13,5 ATTRIBUTE (GREEN)

 

CALL fgl_getkey()

 

END MAIN

 

menu_add_submenu

 

MAIN

 

  OPEN WINDOW c AT 5,20 WITH 15 ROWS, 60 COLUMNS

 

  DISPLAY "menu_add_submenu()" AT 2,2 ATTRIBUTE (MAGENTA, BOLD)

  DISPLAY "adds a submenu to an existing menu;" AT 4,2

  DISPLAY "accepts three parameters:" AT 5,2

  DISPLAY "menu_id" AT 6,3 ATTRIBUTE (MAGENTA)

  DISPLAY " - refers to the menu ID generated by create_menu()" AT 6,10

  DISPLAY "menu_label" AT 7,3 ATTRIBUTE (MAGENTA)

  DISPLAY " - specifies the name of the submenu" AT 7,10

  DISPLAY "enabled" AT 8,3 ATTRIBUTE (MAGENTA)

  DISPLAY " - (optional) specifies whether" AT 8,10

  DISPLAY "the submenu should be enabled or disabled" AT 9,8

  DISPLAY 'LET submenu_id = menu_add_submenu(main_menu_id, "1")' AT 11,5 ATTRIBUTE (MAGENTA)

 

CALL fgl_getkey()

 

END MAIN

 

menu_publish

 

MAIN

 

  OPEN WINDOW d AT 7,30 WITH 15 ROWS, 60 COLUMNS

 

  DISPLAY "menu_publish()" AT 2,2 ATTRIBUTE (CYAN, BOLD)

  DISPLAY "publishes the menu;" AT 4,2

  DISPLAY "only after menu_publish() is executed," AT 5,2

  DISPLAY "you can use the menu_execute() function." AT 6,3

  DISPLAY "CALL menu_publish()" AT 8,5 ATTRIBUTE (CYAN)

 

CALL fgl_getkey()

 

END MAIN

 

execute_menu

 

MAIN

 

  OPEN WINDOW e AT 9,40 WITH 15 ROWS, 60 COLUMNS

 

  DISPLAY "execute_menu()" AT 2,2 ATTRIBUTE (YELLOW, BOLD)

  DISPLAY "monitors the state of the menu;" AT 4,2

  DISPLAY "return the action_id of the menu option" AT 5,2

  DISPLAY "activated by the user." AT 6,3

  DISPLAY "LET action_id = execute_menu()" AT 8,5 ATTRIBUTE (YELLOW)

 

CALL fgl_getkey()

 

END MAIN

 

congratulations

 

MAIN

 

  OPEN WINDOW Congratulations AT 5,135 WITH 5 ROWS, 25 COLUMNS

 

  DISPLAY "!!!CONGRATULATIONS!!!" AT 2,2 ATTRIBUTE (WHITE, BOLD)

  DISPLAY "You have created" AT 3,4

  DISPLAY "your first start menu!" AT 4,4

  DISPLAY "!!!CONGRATULATIONS!!!" AT 5,2 ATTRIBUTE (WHITE, BOLD)

 

CALL fgl_getkey()

 

END MAIN

 

 

Example programs:

Project: mdi-2014

Program: mdi_container_config4gl_startMenu_menuTypeMenu_tabNo

mdi_container_config4gl_startMenu_menuTypeMenu_tabYes

mdi_container_config4gl_startMenu_menuTypeTree_tabNo

mdi_container_config4gl_startMenu_menuTypeTree_tabYes