PreviousUpNext

15.4.1383  src/lib/x-kit/tut/widget/simple-with-menu.pkg

## simple-with-menu.pkg

# Compiled by:
#     src/lib/x-kit/tut/widget/widgets.lib


# Test the popup-menu package.

stipulate
    include package   threadkit;                # threadkit             is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    #
    package fil =  file__premicrothread;        # file__premicrothread  is from   src/lib/std/src/posix/file--premicrothread.pkg
    package xc  =  xclient;                     # xclient               is from   src/lib/x-kit/xclient/xclient.pkg
    #
    package rx  =  run_in_x_window_old;         # run_in_x_window_old   is from   src/lib/x-kit/widget/old/lib/run-in-x-window-old.pkg
    package top =  hostwindow;                  # hostwindow            is from   src/lib/x-kit/widget/old/basic/hostwindow.pkg
    package wg  =  widget;                      # widget                is from   src/lib/x-kit/widget/old/basic/widget.pkg
    package wa  =  widget_attribute_old;        # widget_attribute_old  is from   src/lib/x-kit/widget/old/lib/widget-attribute-old.pkg
    package wy  =  widget_style_old;            # widget_style_old      is from   src/lib/x-kit/widget/old/lib/widget-style-old.pkg
    #
    package pu  =  popup_menu;                  # popup_menu            is from   src/lib/x-kit/widget/old/menu/popup-menu.pkg
    package low =  line_of_widgets;             # line_of_widgets       is from   src/lib/x-kit/widget/old/layout/line-of-widgets.pkg
    package pb  =  pushbuttons;                 # pushbuttons           is from   src/lib/x-kit/widget/old/leaf/pushbuttons.pkg
herein

    package simple_with_menu:   api {
                                    do_it': (List(String), String) -> Void;
                                    do_it:   Void -> Void;
                                    main:   (List( String ), X) -> Void;
                                }
    {

        resources = [
            "*background: forestgreen"
          ];

        menu1 =
            pu::POPUP_MENU
              [
                pu::POPUP_MENU_ITEM("item-1", 1),
                pu::POPUP_MENU_ITEM("item-2", 2),
                pu::POPUP_MENU_ITEM("item-3", 3),

                pu::POPUP_SUBMENU("submenu1",
                    pu::POPUP_MENU
                      [ pu::POPUP_MENU_ITEM("item-4", 4),
                        pu::POPUP_MENU_ITEM("item-5", 5),
                        pu::POPUP_MENU_ITEM("item-6", 6)                    
                      ]
                ),

                pu::POPUP_MENU_ITEM("item-7", 7)
              ];

        fun goodbye root
            = 
            {   make_thread "popup with menu" monitor;
                #
                top::start_widgettree_running_in_hostwindow  hostwindow;

                loop ();
            }
            where
                fun quit ()
                    =
                    {   wg::delete_root_window root;
                        shut_down_thread_scheduler  winix__premicrothread::process::success;
                    };

                style = wg::style_from_strings (root, resources);

                name = wy::make_view
                         { name    =>   wy::style_name [],
                           aliases => [ wy::style_name [] ]
                         };

                view = (name, style);

                args = [ (wa::label, wa::STRING_VAL "Goodbye, Cruel World!") ];

                bttn = pb::make_text_pushbutton_with_click_callback' (root, view, args) quit;

                layout
                    =
                    low::line_of_widgets
                        (root, view,[])
                        (low::VT_CENTER
                          [
                            low::SPACER { min_size=>0,  best_size=>30, max_size=>NULL },
                            low::WIDGET (pb::as_widget bttn),
                            low::SPACER { min_size=>0,  best_size=>30, max_size=>NULL }
                          ]
                        );

                my (widget, mailop)
                    =
                    pu::attach_menu_to_widget
                      ( low::as_widget layout, 
                        [ xc::MOUSEBUTTON 3],
                        menu1
                      );

                fun monitor ()
                    =
                    for (;;) {
                        #
                        n =  block_until_mailop_fires  mailop;

                        fil::write (fil::stdout, "menu choice " + int::to_string n + "\n");
                    };

                hostwindow = top::hostwindow  (root, view,[])  widget;

                fun loop ()
                    =
                    case (fil::read_line  fil::stdin)
                        #
                        THE string
                            =>
                            string ==  "quit\n"  ??  quit ()
                                                 ::  loop ();
                        NULL
                            =>
                            quit ();
                    esac;

            end;                                # fun goodbye

        fun do_it' (debug_flags, server)
            =
            {   xlogger::init debug_flags;
                #
                rx::run_in_x_window_old'  goodbye  [ rx::DISPLAY server ];
            };

        fun do_it ()
            =
            rx::run_in_x_window_old  goodbye;


        fun main (program ! server ! _, _) =>  do_it'([], server);
            main _                         =>  do_it ();
        end;

    };                                          # package simple_with_menu 
end;

## COPYRIGHT (c) 1991 by AT&T Bell Laboratories.  See SMLNJ-COPYRIGHT file for details.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext