PreviousUpNext

15.4.1303  src/lib/tk/src/tests+examples/wbind_ex.pkg

/* ***************************************************************************
   Window event_callbacks example
   Author: ludi
   (C) 1999, Bremen Institute for Safe Systems, Universitaet Bremen
  ************************************************************************** */

# Compiled by:
#     src/lib/tk/src/tests+examples/sources.sublib


package wbind_ex: (weak)  api {
                       go:  Void -> Void;
                    }

{
    include package   tk;
                                                                                my
    ex_window_id  = make_window_id();                                           my
    sec_window_id = make_window_id();                                           my
    txt_id    = make_widget_id();                                               my
    lab_id    = make_widget_id();
                                                                                my
    txt =
        TEXT_WIDGET { widget_id      => txt_id,
                 scrollbars => AT_RIGHT,
                 live_text   => empty_livetext,
                 packing_hints   => [PAD_X 30, PAD_Y 20],
                 traits    => [WIDTH 60, HEIGHT 50, BACKGROUND WHITE,
                               RELIEF RAISED, ACTIVE FALSE],
                 event_callbacks => [] };

    fun clear _ =
        { add_trait txt_id [ACTIVE TRUE];
         clear_text txt_id;
         add_trait txt_id [ACTIVE FALSE];};

    fun ins s _ =
        { add_trait txt_id [ACTIVE TRUE];
         insert_text_end txt_id s;
         add_trait txt_id [ACTIVE FALSE];};

    sec_window =
        make_window {   window_id    => sec_window_id,
                       traits       => [WINDOW_TITLE "non-init Window"],
                  subwidgets  => PACKED [LABEL { widget_id    => lab_id,
                                          packing_hints => [PAD_X 20, PAD_Y 30],
                                          traits  => [   BACKGROUND BLUE,
                                                        FOREGROUND WHITE,
                                                        HEIGHT 3,
                                                        WIDTH 70,
                                                        TEXT "Try to destroy this window (or even main window)!"
                                                    ],
                                          event_callbacks => [] } ],
                  event_callbacks =>
                    [EVENT_CALLBACK (FOCUS_IN, ins "Second window: Focus received\n"),
                     EVENT_CALLBACK (FOCUS_OUT, ins "Second window: Focus lost\n"),
                     EVENT_CALLBACK (CONFIGURE, ins "Second window: Window configured\n"),
                     EVENT_CALLBACK (MAP, ins "Second window: Window mapped (opened)\n"),
                     EVENT_CALLBACK (UNMAP, ins "Second window: Window unmapped (iconified)\n"),
                     EVENT_CALLBACK (VISIBILITY,
                            ins "Second window: Visibility changed\n"),
                     EVENT_CALLBACK (DESTROY, ins "Second window closed!\n"),
                     EVENT_CALLBACK (KEY_PRESS "F2", clear),
                     EVENT_CALLBACK (KEY_PRESS "F3", \\ _ = close_window sec_window_id)],
                  init    => null_callback };

    fun op_sec _
        =
        if (is_open sec_window_id)
            
            insert_text_end txt_id "allready open!\n";
        else
            open_window sec_window;
        fi;

    fun exitmsg _ =
        print "\nThank you for using the Window Event_Callbacks Example!\n\n";

                                                                                my
    buttons
        =
        FRAME {
            widget_id    => make_widget_id(),
            packing_hints => [PACK_AT BOTTOM, FILL ONLY_X, PAD_Y 5],
            traits  => [],
            event_callbacks => [],
            subwidgets  => PACKED [BUTTON { widget_id    => make_widget_id(),
                               packing_hints => [PACK_AT LEFT, PAD_X 5],
                               traits  =>
                                 [TEXT "<F1> Open second Window",
                                  BACKGROUND BLUE, FOREGROUND WHITE,
                                  CALLBACK op_sec],
                               event_callbacks => [] },
                       BUTTON { widget_id    => make_widget_id(),
                               packing_hints => [PACK_AT RIGHT, PAD_X 5],
                               traits  =>
                                 [ TEXT "<F3> Close", WIDTH 8, BACKGROUND BLUE,
                                   FOREGROUND WHITE,
                                   CALLBACK (\\ _ = {   exitmsg();
                                                        close_window ex_window_id;
                                                    }
                                            )
                                 ],
                               event_callbacks => [] },
                       BUTTON { widget_id    => make_widget_id(),
                               packing_hints => [PACK_AT RIGHT],
                               traits  => [TEXT "<F2> Clear", WIDTH 8, BACKGROUND BLUE,
                                  FOREGROUND WHITE, CALLBACK clear],
                               event_callbacks => [] } ]

        };
                                                                                my
    test_window
        =
        make_window {
            window_id   => ex_window_id,
            traits      => [WINDOW_TITLE "Window event_callbacks example"],
            subwidgets  => PACKED [txt, buttons],
            event_callbacks =>
                        [EVENT_CALLBACK (FOCUS_IN, ins "Focus received\n"),
                         EVENT_CALLBACK (FOCUS_OUT, ins "Focus lost\n"),
                         EVENT_CALLBACK (CONFIGURE, ins "Window configured\n"),
                         EVENT_CALLBACK (MAP, ins "Window mapped (opened)\n"),
                         EVENT_CALLBACK (UNMAP, ins "Window unmapped (iconified)\n"),
                         EVENT_CALLBACK (VISIBILITY, ins "Visibility changed\n"),
                         EVENT_CALLBACK (DESTROY, exitmsg),
                         EVENT_CALLBACK (KEY_PRESS "F1", op_sec),
                         EVENT_CALLBACK (KEY_PRESS "F2", clear),
                         EVENT_CALLBACK (KEY_PRESS "F3", \\ _ = close_window ex_window_id)],
            init     => null_callback
        };

    fun go ()
        =
        start_tcl [ test_window ];
};


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext