2006-03-24 03:28:46 -05:00
|
|
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2005-08-31 21:06:13 -04:00
|
|
|
IN: gadgets-presentations
|
2006-08-02 15:17:13 -04:00
|
|
|
USING: arrays definitions gadgets gadgets-borders
|
2006-12-12 20:33:00 -05:00
|
|
|
gadgets-buttons gadgets-labels gadgets-outliners
|
2006-10-07 02:17:32 -04:00
|
|
|
gadgets-panes gadgets-paragraphs gadgets-theme
|
|
|
|
|
generic hashtables tools io kernel prettyprint sequences strings
|
2006-08-26 03:04:02 -04:00
|
|
|
styles words help math models namespaces ;
|
2006-05-20 02:13:44 -04:00
|
|
|
|
|
|
|
|
! Clickable objects
|
2006-11-19 21:13:37 -05:00
|
|
|
TUPLE: presentation object hook ;
|
2006-10-07 02:17:32 -04:00
|
|
|
|
2006-11-19 21:13:37 -05:00
|
|
|
: invoke-presentation ( presentation command -- )
|
|
|
|
|
over dup presentation-hook call
|
|
|
|
|
>r presentation-object r> invoke-command ;
|
|
|
|
|
|
|
|
|
|
: invoke-primary ( presentation -- )
|
|
|
|
|
dup presentation-object primary-operation
|
|
|
|
|
invoke-presentation ;
|
|
|
|
|
|
|
|
|
|
: invoke-secondary ( presentation -- )
|
|
|
|
|
dup presentation-object secondary-operation
|
|
|
|
|
invoke-presentation ;
|
2006-08-25 20:52:13 -04:00
|
|
|
|
2006-08-25 21:29:23 -04:00
|
|
|
: show-mouse-help ( presentation -- )
|
2006-12-12 15:37:51 -05:00
|
|
|
dup presentation-object swap find-world
|
|
|
|
|
[ world-status set-model ] [ drop ] if* ;
|
2006-08-25 21:29:23 -04:00
|
|
|
|
|
|
|
|
: hide-mouse-help ( presentation -- )
|
2006-11-26 21:24:07 -05:00
|
|
|
find-world [ world-status f swap set-model ] when* ;
|
2006-08-25 21:29:23 -04:00
|
|
|
|
2006-09-06 23:26:30 -04:00
|
|
|
M: presentation ungraft* ( presentation -- )
|
|
|
|
|
dup hide-mouse-help delegate ungraft* ;
|
|
|
|
|
|
2006-10-10 01:07:11 -04:00
|
|
|
C: presentation ( gadget object -- button )
|
2006-11-19 21:13:37 -05:00
|
|
|
[ drop ] over set-presentation-hook
|
2006-10-10 01:07:11 -04:00
|
|
|
[ set-presentation-object ] keep
|
2006-11-19 21:13:37 -05:00
|
|
|
swap [ invoke-primary ] <roll-button>
|
2006-10-10 01:07:11 -04:00
|
|
|
over set-gadget-delegate ;
|
|
|
|
|
|
2006-11-21 19:17:09 -05:00
|
|
|
: (command-button) ( target command -- label quot )
|
2006-10-10 01:07:11 -04:00
|
|
|
dup command-name -rot
|
2006-11-21 19:17:09 -05:00
|
|
|
[ invoke-command drop ] curry curry ;
|
|
|
|
|
|
|
|
|
|
: <command-button> ( target command -- button )
|
|
|
|
|
(command-button) <bevel-button> ;
|
2006-10-10 01:07:11 -04:00
|
|
|
|
2006-11-30 02:55:55 -05:00
|
|
|
: <toolbar> ( target classes -- toolbar )
|
|
|
|
|
[ commands "toolbar" swap hash ] map concat
|
|
|
|
|
[ <command-button> ] map-with
|
|
|
|
|
make-shelf ;
|
|
|
|
|
|
2006-12-05 01:23:57 -05:00
|
|
|
: <menu-item> ( hook target command -- button )
|
|
|
|
|
rot >r
|
|
|
|
|
(command-button) [ hand-clicked get find-world hide-glass ]
|
2006-12-10 14:59:32 -05:00
|
|
|
r> 3append <roll-button> ;
|
2006-11-18 03:51:34 -05:00
|
|
|
|
2006-12-05 01:23:57 -05:00
|
|
|
: <commands-menu> ( hook target commands -- gadget )
|
|
|
|
|
[ >r 2dup r> <menu-item> ] map 2nip make-filled-pile
|
2006-11-21 19:17:09 -05:00
|
|
|
<default-border>
|
|
|
|
|
dup menu-theme ;
|
2006-10-10 01:07:11 -04:00
|
|
|
|
2006-10-23 23:54:08 -04:00
|
|
|
: operations-menu ( presentation -- )
|
2006-12-05 01:23:57 -05:00
|
|
|
dup
|
|
|
|
|
dup presentation-hook curry
|
|
|
|
|
over presentation-object
|
|
|
|
|
dup object-operations <commands-menu>
|
2006-10-10 01:07:11 -04:00
|
|
|
swap show-menu ;
|
|
|
|
|
|
2006-08-25 20:52:13 -04:00
|
|
|
presentation H{
|
2006-10-10 01:07:11 -04:00
|
|
|
{ T{ button-down f f 3 } [ operations-menu ] }
|
2006-10-07 02:25:29 -04:00
|
|
|
{ T{ mouse-leave } [ dup hide-mouse-help button-update ] }
|
2006-10-09 14:51:09 -04:00
|
|
|
{ T{ motion } [ dup show-mouse-help button-update ] }
|
2006-08-24 22:44:42 -04:00
|
|
|
} set-gestures
|
|
|
|
|
|
2006-08-25 21:29:23 -04:00
|
|
|
! Presentation help bar
|
|
|
|
|
: <presentation-help> ( model -- gadget )
|
2006-12-12 15:37:51 -05:00
|
|
|
[ [ summary ] [ "" ] if* ] <filter> <label-control>
|
|
|
|
|
dup reverse-video-theme ;
|
2006-08-25 21:29:23 -04:00
|
|
|
|
2005-12-17 20:03:41 -05:00
|
|
|
! Character styles
|
|
|
|
|
|
|
|
|
|
: apply-style ( style gadget key quot -- style gadget )
|
2006-07-09 20:47:01 -04:00
|
|
|
>r pick hash r> when* ; inline
|
2005-12-17 20:03:41 -05:00
|
|
|
|
|
|
|
|
: apply-foreground-style ( style gadget -- style gadget )
|
|
|
|
|
foreground [ over set-label-color ] apply-style ;
|
|
|
|
|
|
|
|
|
|
: apply-background-style ( style gadget -- style gadget )
|
|
|
|
|
background [ <solid> over set-gadget-interior ] apply-style ;
|
|
|
|
|
|
|
|
|
|
: specified-font ( style -- font )
|
2006-01-20 01:26:50 -05:00
|
|
|
[ font swap hash [ "monospace" ] unless* ] keep
|
2005-12-17 20:03:41 -05:00
|
|
|
[ font-style swap hash [ plain ] unless* ] keep
|
|
|
|
|
font-size swap hash [ 12 ] unless* 3array ;
|
|
|
|
|
|
|
|
|
|
: apply-font-style ( style gadget -- style gadget )
|
|
|
|
|
over specified-font over set-label-font ;
|
|
|
|
|
|
2006-08-25 20:52:13 -04:00
|
|
|
: apply-presentation-style ( style gadget -- style gadget )
|
2006-10-10 01:07:11 -04:00
|
|
|
presented [ <presentation> ] apply-style ;
|
2005-12-17 20:03:41 -05:00
|
|
|
|
2006-08-25 20:52:13 -04:00
|
|
|
: <styled-label> ( style text -- gadget )
|
2005-12-17 20:03:41 -05:00
|
|
|
<label>
|
|
|
|
|
apply-foreground-style
|
|
|
|
|
apply-background-style
|
|
|
|
|
apply-font-style
|
2006-08-25 20:52:13 -04:00
|
|
|
apply-presentation-style
|
2005-12-17 20:03:41 -05:00
|
|
|
nip ;
|
|
|
|
|
|
|
|
|
|
! Paragraph styles
|
|
|
|
|
|
|
|
|
|
: apply-wrap-style ( style pane -- style pane )
|
|
|
|
|
wrap-margin [
|
2006-07-09 20:47:01 -04:00
|
|
|
2dup <paragraph> swap set-pane-prototype
|
|
|
|
|
<paragraph> over set-pane-current
|
2005-12-17 20:03:41 -05:00
|
|
|
] apply-style ;
|
|
|
|
|
|
|
|
|
|
: apply-border-width-style ( style gadget -- style gadget )
|
|
|
|
|
border-width [ <border> ] apply-style ;
|
|
|
|
|
|
|
|
|
|
: apply-border-color-style ( style gadget -- style gadget )
|
|
|
|
|
border-color [
|
|
|
|
|
<solid> over set-gadget-boundary
|
|
|
|
|
] apply-style ;
|
|
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: apply-page-color-style ( style gadget -- style gadget )
|
|
|
|
|
page-color [
|
|
|
|
|
<solid> over set-gadget-interior
|
|
|
|
|
] apply-style ;
|
|
|
|
|
|
|
|
|
|
: apply-outliner-style ( style gadget -- style gadget )
|
2006-12-12 20:33:00 -05:00
|
|
|
outline [ [ make-pane ] curry <outliner> ] apply-style ;
|
2005-12-19 02:12:40 -05:00
|
|
|
|
|
|
|
|
: <styled-paragraph> ( style pane -- gadget )
|
2005-12-17 20:03:41 -05:00
|
|
|
apply-wrap-style
|
|
|
|
|
apply-border-width-style
|
|
|
|
|
apply-border-color-style
|
2005-12-19 02:12:40 -05:00
|
|
|
apply-page-color-style
|
2006-08-25 20:52:13 -04:00
|
|
|
apply-presentation-style
|
2005-12-19 02:12:40 -05:00
|
|
|
apply-outliner-style
|
2005-12-17 20:03:41 -05:00
|
|
|
nip ;
|
2005-12-16 21:12:35 -05:00
|
|
|
|
2006-06-09 22:17:12 -04:00
|
|
|
: styled-pane ( quot style -- gadget )
|
2005-12-17 20:03:41 -05:00
|
|
|
#! Create a pane, call the quotation to fill it out.
|
2005-12-19 02:12:40 -05:00
|
|
|
>r <pane> dup r> swap <styled-paragraph>
|
|
|
|
|
>r swap with-pane r> ; inline
|
2005-12-16 22:24:39 -05:00
|
|
|
|
2006-08-31 21:58:15 -04:00
|
|
|
: apply-table-gap-style ( style grid -- style grid )
|
2006-06-26 01:53:05 -04:00
|
|
|
table-gap [ over set-grid-gap ] apply-style ;
|
|
|
|
|
|
2006-08-31 21:58:15 -04:00
|
|
|
: apply-table-border-style ( style grid -- style grid )
|
2006-06-26 01:53:05 -04:00
|
|
|
table-border [ <grid-lines> over set-gadget-boundary ]
|
|
|
|
|
apply-style ;
|
|
|
|
|
|
|
|
|
|
: styled-grid ( style grid -- grid )
|
2006-06-17 16:51:44 -04:00
|
|
|
<grid>
|
2006-06-26 01:53:05 -04:00
|
|
|
apply-table-gap-style
|
|
|
|
|
apply-table-border-style
|
|
|
|
|
nip ;
|
2006-06-17 16:00:10 -04:00
|
|
|
|
2006-06-09 22:17:12 -04:00
|
|
|
: <pane-grid> ( quot style grid -- gadget )
|
|
|
|
|
[
|
|
|
|
|
[ pick pick >r >r -rot styled-pane r> r> rot ] map
|
2006-06-17 16:00:10 -04:00
|
|
|
] map styled-grid nip ;
|
2006-06-09 22:17:12 -04:00
|
|
|
|
2006-10-04 21:33:09 -04:00
|
|
|
M: pane-stream with-stream-table
|
2006-06-14 02:16:53 -04:00
|
|
|
>r rot <pane-grid> r> print-gadget ;
|
2006-06-09 22:17:12 -04:00
|
|
|
|
2006-10-04 21:33:09 -04:00
|
|
|
M: pane-stream with-nested-stream
|
2006-06-09 22:17:12 -04:00
|
|
|
>r styled-pane r> write-gadget ;
|
2006-01-21 02:37:39 -05:00
|
|
|
|
|
|
|
|
! Stream utilities
|
2006-08-15 03:01:24 -04:00
|
|
|
M: pack stream-close drop ;
|
2006-01-21 02:37:39 -05:00
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: paragraph stream-close drop ;
|
2006-01-21 02:37:39 -05:00
|
|
|
|
|
|
|
|
: gadget-write ( string gadget -- )
|
2006-08-26 03:20:58 -04:00
|
|
|
over empty? [
|
|
|
|
|
2drop
|
|
|
|
|
] [
|
|
|
|
|
>r <label> dup text-theme r> add-gadget
|
|
|
|
|
] if ;
|
2006-01-21 02:37:39 -05:00
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: pack stream-write gadget-write ;
|
2006-01-21 02:37:39 -05:00
|
|
|
|
|
|
|
|
: gadget-bl ( style stream -- )
|
2006-08-25 20:52:13 -04:00
|
|
|
>r " " <styled-label> <word-break-gadget> r> add-gadget ;
|
2006-01-21 02:37:39 -05:00
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: paragraph stream-write
|
2006-01-21 02:37:39 -05:00
|
|
|
swap " " split
|
|
|
|
|
[ over gadget-write ] [ H{ } over gadget-bl ] interleave
|
|
|
|
|
drop ;
|
|
|
|
|
|
|
|
|
|
: gadget-write1 ( char gadget -- )
|
|
|
|
|
>r ch>string r> stream-write ;
|
|
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: pack stream-write1 gadget-write1 ;
|
2006-01-21 02:37:39 -05:00
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: paragraph stream-write1
|
2006-01-21 02:37:39 -05:00
|
|
|
over CHAR: \s =
|
|
|
|
|
[ H{ } swap gadget-bl drop ] [ gadget-write1 ] if ;
|
|
|
|
|
|
|
|
|
|
: gadget-format ( string style stream -- )
|
2006-06-27 19:57:04 -04:00
|
|
|
pick empty?
|
2006-08-25 20:52:13 -04:00
|
|
|
[ 3drop ] [ >r swap <styled-label> r> add-gadget ] if ;
|
2006-01-21 02:37:39 -05:00
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: pack stream-format
|
2006-01-21 02:37:39 -05:00
|
|
|
gadget-format ;
|
|
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: paragraph stream-format
|
2006-01-21 02:37:39 -05:00
|
|
|
presented pick hash [
|
|
|
|
|
gadget-format
|
|
|
|
|
] [
|
|
|
|
|
rot " " split
|
|
|
|
|
[ pick pick gadget-format ]
|
|
|
|
|
[ 2dup gadget-bl ] interleave
|
|
|
|
|
2drop
|
|
|
|
|
] if ;
|