PreviousUpNext

15.3.656  src/lib/x-kit/widget/leaf/diamondbutton.api

## diamondbutton.api
#

# Compiled by:
#     src/lib/x-kit/widget/xkit-widget.sublib


###                        "We in science are spoiled by the success of mathematics.
###                         Mathematics is the study of problems so simple
###                         that they have good solutions."
###
###                                                   -- Whitfield Diffie 



stipulate
    include package   threadkit;                                                # threadkit                     is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    include package   geometry2d;                                               # geometry2d                    is from   src/lib/std/2d/geometry2d.pkg
    #
    package gd  =  gui_displaylist;                                             # gui_displaylist               is from   src/lib/x-kit/widget/theme/gui-displaylist.pkg
    package gt  =  guiboss_types;                                               # guiboss_types                 is from   src/lib/x-kit/widget/gui/guiboss-types.pkg
    package wt  =  widget_theme;                                                # widget_theme                  is from   src/lib/x-kit/widget/theme/widget/widget-theme.pkg
    package wi  =  widget_imp;                                                  # widget_imp                    is from   src/lib/x-kit/widget/xkit/theme/widget/default/look/widget-imp.pkg
    package g2d =  geometry2d;                                                  # geometry2d                    is from   src/lib/std/2d/geometry2d.pkg
    package evt =  gui_event_types;                                             # gui_event_types               is from   src/lib/x-kit/widget/gui/gui-event-types.pkg
    package mtx =  rw_matrix;                                                   # rw_matrix                     is from   src/lib/std/src/rw-matrix.pkg
    package r8  =  rgb8;                                                        # rgb8                          is from   src/lib/x-kit/xclient/src/color/rgb8.pkg
herein

    # This api is implemented in:
    #
    #     src/lib/x-kit/widget/leaf/diamondbutton.pkg
    #
    api Diamondbutton {
        #
        package t: api {                                                        # "t" for "type"
            #
            Button_Type         = MOMENTARY_CONTACT
                                | PUSH_ON_PUSH_OFF
                                | IGNORE_MOUSECLICKS
                                ;
        };


        App_To_Diamondbutton
          =
          { id:                         Id,
            #
            get_active:                 Void -> Bool,
            get_state:                  Void -> Bool,
            #
            get_button_relief:          Void -> wt::Relief,                     # 
            get_button_type:            Void -> t::Button_Type,                 # 
            #
            get_button_text:            Void -> Null_Or(String),
            get_button_on_text:         Void -> Null_Or(String),
            get_button_off_text:        Void -> Null_Or(String),

            set_button_text:            Null_Or(String) -> Void,
            set_button_on_text:         Null_Or(String) -> Void,
            set_button_off_text:        Null_Or(String) -> Void,
            #
            set_active_to:              Bool -> Void,
            set_state_to:               Bool -> Void,                           # Also calls gadget_to_guiboss.needs_redraw_gadget_request(id);
            set_button_relief_to:       wt::Relief -> Void                      # Also calls gadget_to_guiboss.needs_redraw_gadget_request(id);
          };



        Redraw_Fn_Arg
            =
            REDRAW_FN_ARG
              {
                id:                             Id,                             # Unique Id for widget.
                doc:                            String,                         # Human-readable description of this widget, for debug and inspection.
                frame_number:                   Int,                            # 1,2,3,... Purely for convenience of widget, guiboss-imp makes no use of this.
                frame_indent_hint:              gt::Frame_Indent_Hint,
                site:                           g2d::Box,                       # Window rectangle in which to draw.
                popup_nesting_depth:            Int,                            # 0 for gadgets on basewindow, 1 for gadgets on popup on basewindow, 2 for gadgets on popup on popup, etc.
                #
                duration_in_seconds:            Float,                          # If state has changed look-imp should call note_changed_gadget_foreground() before this time is up. Also useful for motionblur.
                widget_to_guiboss:              gt::Widget_To_Guiboss,
                gadget_mode:                    gt::Gadget_Mode,
                #
                theme:                          wt::Widget_Theme,
                do:                             (Void -> Void) -> Void,         # Used by widget subthreads to execute code in main widget microthread.
                to:                             Replyqueue,                     # Used to call 'pass_*' methods in other imps.
                palette:                        wt::Gadget_Palette,
                #
                default_redraw_fn:              Redraw_Fn,
                #
                button_state:                   Bool,                           # Is the button ON or OFF?
                button_type:                    t::Button_Type,                 # Is the button push-on-push-off or momentary-contact?
                button_relief:                  wt::Relief,                     # Is the button outline a slope, a ridge, or a flat band?

                text:                           Null_Or(String),
                fonts:                          List(String),
                font_weight:                    Null_Or(wt::Font_Weight),
                font_size:                      Null_Or(Int),

                margin:                         Int,
                thick:                          Int
              }

        withtype
        Redraw_Fn
          =
          Redraw_Fn_Arg
          ->
          { displaylist:                gd::Gui_Displaylist,
            point_in_gadget:            Null_Or(g2d::Point -> Bool),            # 
            pixels_high_min:            Int,
            pixels_wide_min:            Int
          }
          ;



        Mouse_Click_Fn_Arg
            =
            MOUSE_CLICK_FN_ARG                                                  # Needs to be a sumtype because of recursive reference in default_mouse_click_fn.
              {
                id:                             Id,                             # Unique Id for widget.
                doc:                            String,                         # Human-readable description of this widget, for debug and inspection.
                event:                          gt::Mousebutton_Event,          # MOUSEBUTTON_PRESS or MOUSEBUTTON_RELEASE.
                button:                         evt::Mousebutton,               # Which mousebutton was pressed/released.
                point:                          g2d::Point,                     # Where the mouse was.
                widget_layout_hint:             gt::Widget_Layout_Hint,
                frame_indent_hint:              gt::Frame_Indent_Hint,
                site:                           g2d::Box,                       # Widget's assigned area in window coordinates.
                modifier_keys_state:            evt::Modifier_Keys_State,       # State of the modifier keys (shift, ctrl...).
                mousebuttons_state:             evt::Mousebuttons_State,        # State of mouse buttons as a bool record.
                widget_to_guiboss:              gt::Widget_To_Guiboss,
                theme:                          wt::Widget_Theme,
                do:                             (Void -> Void) -> Void,         # Used by widget subthreads to execute code in main widget microthread.
                to:                             Replyqueue,                     # Used to call 'pass_*' methods in other imps.
                #
                default_mouse_click_fn:         Mouse_Click_Fn,
                #
                button_state:                   Bool,                           # Is the button ON or OFF?
                button_type:                        t::Button_Type,             # Is the button push-on-push-off or momentary-contact?
                button_relief:                  Ref(wt::Relief),                # Is the button outline a slope, a ridge, or a flat band?
                #
                initial_state:                  Bool,                           # Original state of button.
                note_state:                     Bool -> Void,                   # Change state of button. This takes care of notifying our state-watchers. (Does NOT call needs_redraw_gadget_request.)
                needs_redraw_gadget_request:    Void -> Void                    # Notify guiboss-imp that this button needs to be redrawn (i.e., sent a redraw_gadget_request()).
              }
        withtype
        Mouse_Click_Fn =  Mouse_Click_Fn_Arg -> Void;



        Mouse_Drag_Fn_Arg
            =
            MOUSE_DRAG_FN_ARG
              {
                id:                             Id,                             # Unique Id for widget.
                doc:                            String,                         # Human-readable description of this widget, for debug and inspection.
                event_point:                    g2d::Point,
                start_point:                    g2d::Point,
                last_point:                     g2d::Point,
                widget_layout_hint:             gt::Widget_Layout_Hint,
                frame_indent_hint:              gt::Frame_Indent_Hint,
                site:                           g2d::Box,                       # Widget's assigned area in window coordinates.
                phase:                          gt::Drag_Phase, 
                button:                         evt::Mousebutton,
                modifier_keys_state:            evt::Modifier_Keys_State,       # State of the modifier keys (shift, ctrl...).
                mousebuttons_state:             evt::Mousebuttons_State,        # State of mouse buttons as a bool record.
                widget_to_guiboss:              gt::Widget_To_Guiboss,
                theme:                          wt::Widget_Theme,
                do:                             (Void -> Void) -> Void,         # Used by widget subthreads to execute code in main widget microthread.
                to:                             Replyqueue,                     # Used to call 'pass_*' methods in other imps.
                #
                default_mouse_drag_fn:          Mouse_Drag_Fn,
                #
                button_state:                   Bool,                           # Is the button ON or OFF?
                button_type:                        t::Button_Type,             # Is the button push-on-push-off or momentary-contact?
                button_relief:                  Ref(wt::Relief),                # Is the button outline a slope, a ridge, or a flat band?
                #
                initial_state:                  Bool,                           # Original state of button.
                note_state:                     Bool -> Void,                   # Change state of button. This takes care of notifying our state-watchers. (Does NOT call needs_redraw_gadget_request.)
                needs_redraw_gadget_request:    Void -> Void                    # Notify guiboss-imp that this button needs to be redrawn (i.e., sent a redraw_gadget_request()).
              }
        withtype
        Mouse_Drag_Fn =  Mouse_Drag_Fn_Arg -> Void;



        Mouse_Transit_Fn_Arg                                                    # Note that buttons are always all up in a mouse-transit event -- otherwise it is a mouse-drag event.
            =
            MOUSE_TRANSIT_FN_ARG
              {
                id:                             Id,                             # Unique Id for widget.
                doc:                            String,                         # Human-readable description of this widget, for debug and inspection.
                event_point:                    g2d::Point,
                widget_layout_hint:             gt::Widget_Layout_Hint,
                frame_indent_hint:              gt::Frame_Indent_Hint,
                site:                           g2d::Box,                       # Widget's assigned area in window coordinates.
                transit:                        gt::Gadget_Transit,             # Mouse is entering (CAME) or leaving (LEFT) widget, or moving (MOVE) across it.
                modifier_keys_state:            evt::Modifier_Keys_State,       # State of the modifier keys (shift, ctrl...).
                widget_to_guiboss:              gt::Widget_To_Guiboss,
                theme:                          wt::Widget_Theme,
                do:                             (Void -> Void) -> Void,         # Used by widget subthreads to execute code in main widget microthread.
                to:                             Replyqueue,                     # Used to call 'pass_*' methods in other imps.
                #
                default_mouse_transit_fn:       Mouse_Transit_Fn,
                #
                button_state:                   Bool,                           # Is the button ON or OFF?
                button_type:                        t::Button_Type,             # Is the button push-on-push-off or momentary-contact?
                button_relief:                  Ref(wt::Relief),                # Is the button outline a slope, a ridge, or a flat band?
                #
                initial_state:                  Bool,                           # Original state of button.
                note_state:                     Bool -> Void,                   # Change state of button. This takes care of notifying our state-watchers. (Does NOT call needs_redraw_gadget_request.)
                needs_redraw_gadget_request:    Void -> Void                    # Notify guiboss-imp that this button needs to be redrawn (i.e., sent a redraw_gadget_request()).
              }
        withtype
        Mouse_Transit_Fn =  Mouse_Transit_Fn_Arg -> Void;



        Key_Event_Fn_Arg
            =
            KEY_EVENT_FN_ARG
              {
                id:                             Id,                             # Unique Id for widget.
                doc:                            String,                         # Human-readable description of this widget, for debug and inspection.
                keystroke:                      gt::Keystroke_Info,             # Keystring etc for event.
                widget_layout_hint:             gt::Widget_Layout_Hint,
                frame_indent_hint:              gt::Frame_Indent_Hint,
                site:                           g2d::Box,                       # Widget's assigned area in window coordinates.
                widget_to_guiboss:              gt::Widget_To_Guiboss,
                guiboss_to_widget:              gt::Guiboss_To_Widget,          # Used by textpane.pkg keystroke-macro stuff to synthesize fake keystroke events to widget.
                theme:                          wt::Widget_Theme,
                do:                             (Void -> Void) -> Void,         # Used by widget subthreads to execute code in main widget microthread.
                to:                             Replyqueue,                     # Used to call 'pass_*' methods in other imps.
                #
                default_key_event_fn:           Key_Event_Fn,
                #
                button_state:                   Bool,                           # Is the button ON or OFF?
                button_type:                        t::Button_Type,             # Is the button push-on-push-off or momentary-contact?
                button_relief:                  Ref(wt::Relief),                # Is the button outline a slope, a ridge, or a flat band?
                #
                initial_state:                  Bool,                           # Original state of button.
                note_state:                     Bool -> Void,                   # Change state of button. This takes care of notifying our state-watchers. (Does NOT call needs_redraw_gadget_request.)
                needs_redraw_gadget_request:    Void -> Void                    # Notify guiboss-imp that this button needs to be redrawn (i.e., sent a redraw_gadget_request()).
              }
        withtype
        Key_Event_Fn =  Key_Event_Fn_Arg -> Void;



        Option  = PIXELS_SQUARE         Int                                     # ==  [ PIXELS_HIGH_MIN i,  PIXELS_WIDE_MIN i,  PIXELS_HIGH_CUT 0.0,  PIXELS_WIDE_CUT 0.0 ]
                #
                | PIXELS_HIGH_MIN       Int                                     # Give widget at least this many pixels vertically.
                | PIXELS_WIDE_MIN       Int                                     # Give widget at least this many pixels horizontally.
                #
                | PIXELS_HIGH_CUT       Float                                   # Give widget this big a share of remaining pixels vertically.    0.0 means to never expand it beyond its minimum size.
                | PIXELS_WIDE_CUT       Float                                   # Give widget this big a share of remaining pixels horizontally.  0.0 means to never expand it beyond its minimum size.
                #
                | INITIAL_STATE         Bool
                | INITIALLY_ACTIVE      Bool
                #
                | MOMENTARY_CONTACT                                             # State is non-default (opposite of INITIAL_STATE) only between mouse downclick and upclick.
                | PUSH_ON_PUSH_OFF                                              # Mouse downclicks toggle state between TRUE and FALSE.
                | IGNORE_MOUSECLICKS                                            # Mouseclicks to not affect state.
                #
                | BODY_COLOR                            rgb::Rgb
                | BODY_COLOR_WITH_MOUSEFOCUS            rgb::Rgb
                | BODY_COLOR_WHEN_ON                    rgb::Rgb
                | BODY_COLOR_WHEN_ON_WITH_MOUSEFOCUS    rgb::Rgb
                #
                | ID                    Id
                | DOC                   String
                #
                | RELIEF                wt::Relief                              # Should button boundary be drawn flat, raised, sunken, ridged or grooved?
                | MARGIN                Int                                     # How many pixels to inset button relative to its assigned window site.  Default is 4.
                | THICK                 Int                                     # Thickness of lines (well, polygons) forming button.  Default is 5.
                #
                | TEXT                  String                                  # Text to draw inside button.  Default is "".
                | ON_TEXT               String                                  # Text to draw inside button when switch is ON.   Default is TEXT else "".
                | OFF_TEXT              String                                  # Text to draw inside button when switch is OFF.  Default is TEXT else "".
                #
                | FONT_SIZE             Int                                     # Show any text in this pointsize.  Default is 12.
                | FONTS                 List(String)                            # Override theme font:  Font to use for text label, e.g. "-*-courier-bold-r-*-*-20-*-*-*-*-*-*-*".  We'll use the first font in list which is found on X server, else "9x15" (which X guarantees to have).
                #
                | ROMAN                                                         # Show any text in plain  font from widget-theme.  This is the default.
                | ITALIC                                                        # Show any text in italic font from widget-theme.
                | BOLD                                                          # Show any text in bold   font from widget-theme.  NB: Text is either bold or italic, not both.
                #
                | REDRAW_FN             Redraw_Fn                               # Application-specific handler for widget redraw.
                | MOUSE_CLICK_FN        Mouse_Click_Fn                          # Application-specific handler for mousebutton clicks.
                | MOUSE_DRAG_FN         Mouse_Drag_Fn                           # Application-specific handler for mouse drags.
                | MOUSE_TRANSIT_FN      Mouse_Transit_Fn                        # Application-specific handler for mouse crossings.
                | KEY_EVENT_FN          Key_Event_Fn                            # Application-specific handler for keyboard input.
                #
                | BOOL_OUT              (Bool -> Void)                          # Widget's current state              will be sent to these fns each time state changes.
                | PORTWATCHER           (Null_Or(App_To_Diamondbutton) -> Void) # Widget's app port                   will be sent to these fns at widget startup.
                | SITEWATCHER           (Null_Or((Id,g2d::Box)) -> Void)        # Widget's site in window coordinates will be sent to these fns each time it changes.

                ;                                                               # To help prevent deadlock, watcher fns should be fast and nonblocking, typically just setting a var or entering something into a mailqueue.
                
        with:  List(Option) -> gt::Gp_Widget_Type;                              # The point of the 'with' name is that GUI coders can write 'diamondbutton::with { this => that, foo => bar, ... }.'
    };
end;


## COPYRIGHT (c) 1994 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