PreviousUpNext

15.4.1554  src/lib/x-kit/widget/old/wrapper/size-preference-wrapper.pkg

## size-preference-wrapper.pkg

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



# Widget wrappers to constrain widget's shape.


###           "Glory is fleeting, but obscurity is forever."
###
###                            -- Napoleon Bonaparte

stipulate
    include package   threadkit;                                        # threadkit                     is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    #
    package xc =  xclient;                                              # xclient                       is from   src/lib/x-kit/xclient/xclient.pkg
    #
    package wg =  widget;                                               # widget                        is from   src/lib/x-kit/widget/old/basic/widget.pkg
    package g2d=  geometry2d;                                           # geometry2d                    is from   src/lib/std/2d/geometry2d.pkg
herein

    package   size_preference_wrapper
    : (weak)  Size_Preference_Wrapper                                   # Size_Preference_Wrapper       is from   src/lib/x-kit/widget/old/wrapper/size-preference-wrapper.api
    {
        stipulate 

            fun do_shape
                    shape_fn            # make_tight_sized_preference_wrapper() or make_loose_sized_preference_wrapper()
                    widget
                =
                shape_fn (widget,  wg::preferred_size  widget);

            fun dummy x = x;

        herein

            fun make_size_preference_wrapper wrapfn
                {
                  child,
                  size_preference_fn => bounds,
                  resize_fn => resize
                }
                =
                {   size_preference_thunk_of
                        =
                        wg::size_preference_thunk_of  child;

                    fun realize_widget { window, window_size,  kidplug =>  xc::KIDPLUG { from_mouse', from_keyboard', from_other', to_mom } }
                        =
                        {   oslot = make_mailslot ();
                            #
                            fun out_mailop slot x
                                =
                                put_in_mailslot' (slot, x);

                            ckidplug =  xc::KIDPLUG { from_keyboard', from_mouse', from_other', to_mom => out_mailop oslot };

                            childco = wrapfn (take_from_mailslot' oslot);

                            fun loop ()
                                =
                                loop (
                                    case (block_until_mailop_fires  childco)
                                        #
                                        xc::REQ_DESTRUCTION
                                            =>
                                            block_until_mailop_fires  (to_mom  xc::REQ_DESTRUCTION);

                                        xc::REQ_RESIZE
                                            => 
                                            if (resize  size_preference_thunk_of)
                                                #
                                                block_until_mailop_fires  (to_mom  xc::REQ_RESIZE);
                                            fi;
                                    esac
                                  );

                            make_thread "shape" loop;

                            wg::realize_widget  child  { kidplug=>ckidplug, window, window_size };
                        };

                    wg::make_widget
                      {
                        root_window =>  wg::root_window_of  child,

                        args =>  wg::args_fn  child,

                        size_preference_thunk_of =>   \\ () = bounds size_preference_thunk_of,

                        realize_widget
                      };
                };


            fun make_tight_sized_preference_wrapper (child, { wide, high } )
                =
                {   bounds = wg::make_tight_size_preference (wide, high);

                    make_size_preference_wrapper  dummy
                      {
                        child,
                        size_preference_fn =>  \\ _ = bounds, 
                        resize_fn          =>  \\ _ = FALSE
                      };
                };


            fun make_loose_sized_preference_wrapper (child, { wide, high } )
                =
                {   col_preference  =  wg::INT_PREFERENCE {  start_at => 0,  step_by => 1,  min_steps => 1,  best_steps => wide,  max_steps => NULL  };
                    row_preference  =  wg::INT_PREFERENCE {  start_at => 0,  step_by => 1,  min_steps => 1,  best_steps => high,  max_steps => NULL  };

                    fun size_preference_fn  _
                        =
                        { col_preference,
                          row_preference
                        };

                    make_size_preference_wrapper  dummy
                        {
                          child,
                          size_preference_fn,
                          resize_fn =>   \\ _ = TRUE
                        };
                };

            make_tight_size_preference_wrapper =  do_shape  make_tight_sized_preference_wrapper;
            make_loose_size_preference_wrapper =  do_shape  make_loose_sized_preference_wrapper;

            make_size_preference_wrapper =  make_size_preference_wrapper  wg::wrap_queue;

        end;                                    # stipulate
    };                                          # package size_preference_wrapper

end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext