2006-06-07 23:51:28 -04: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-panes
|
2006-12-13 23:40:56 -05:00
|
|
|
USING: arrays gadgets gadgets-borders gadgets-buttons
|
|
|
|
|
gadgets-labels gadgets-scrolling gadgets-paragraphs
|
|
|
|
|
gadgets-theme gadgets-presentations gadgets-outliners
|
|
|
|
|
generic hashtables io kernel namespaces sequences styles
|
|
|
|
|
strings ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
2006-07-19 20:23:08 -04:00
|
|
|
TUPLE: pane output current prototype scrolls? ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
|
: add-output 2dup set-pane-output add-gadget ;
|
2005-06-27 16:50:21 -04:00
|
|
|
|
2006-07-19 20:23:08 -04:00
|
|
|
: add-current 2dup set-pane-current add-gadget ;
|
2005-12-16 21:12:35 -05:00
|
|
|
|
|
|
|
|
: prepare-line ( pane -- )
|
2006-07-19 20:23:08 -04:00
|
|
|
dup pane-prototype clone swap add-current ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
2005-08-31 21:06:13 -04:00
|
|
|
: pane-clear ( pane -- )
|
2006-07-19 20:23:08 -04:00
|
|
|
dup
|
|
|
|
|
pane-output clear-incremental
|
|
|
|
|
pane-current clear-gadget ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
2005-12-17 00:12:32 -05:00
|
|
|
C: pane ( -- pane )
|
2005-08-31 21:06:13 -04:00
|
|
|
<pile> over set-delegate
|
2005-12-17 00:12:32 -05:00
|
|
|
<shelf> over set-pane-prototype
|
2005-08-31 21:06:13 -04:00
|
|
|
<pile> <incremental> over add-output
|
2005-12-28 20:25:17 -05:00
|
|
|
dup prepare-line ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
2006-10-04 23:30:17 -04:00
|
|
|
: scroll-pane ( pane -- )
|
|
|
|
|
dup pane-scrolls? [ scroll>bottom ] [ drop ] if ;
|
|
|
|
|
|
|
|
|
|
TUPLE: pane-stream pane ;
|
|
|
|
|
|
2005-08-24 21:52:10 -04:00
|
|
|
: prepare-print ( current -- gadget )
|
2005-10-29 23:25:38 -04:00
|
|
|
dup gadget-children {
|
|
|
|
|
{ [ dup empty? ] [ 2drop "" <label> ] }
|
|
|
|
|
{ [ dup length 1 = ] [ nip first ] }
|
|
|
|
|
{ [ t ] [ drop ] }
|
|
|
|
|
} cond ;
|
2005-08-24 21:52:10 -04:00
|
|
|
|
2006-10-04 23:30:17 -04:00
|
|
|
: pane-terpri ( pane -- )
|
|
|
|
|
dup pane-current dup unparent prepare-print
|
|
|
|
|
over pane-output add-incremental
|
|
|
|
|
prepare-line ;
|
|
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: pane-write ( pane seq -- )
|
|
|
|
|
[ over pane-current stream-write ]
|
2006-10-04 23:30:17 -04:00
|
|
|
[ dup pane-terpri ] interleave drop ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: pane-format ( style pane seq -- )
|
|
|
|
|
[ pick pick pane-current stream-format ]
|
2006-10-04 23:30:17 -04:00
|
|
|
[ dup pane-terpri ] interleave 2drop ;
|
2006-10-04 17:33:02 -04:00
|
|
|
|
|
|
|
|
: do-pane-stream ( pane-stream quot -- )
|
|
|
|
|
>r pane-stream-pane r> over slip scroll-pane ; inline
|
|
|
|
|
|
|
|
|
|
M: pane-stream stream-terpri
|
2006-10-04 23:30:17 -04:00
|
|
|
[ pane-terpri ] do-pane-stream ;
|
2006-10-04 17:33:02 -04:00
|
|
|
|
|
|
|
|
M: pane-stream stream-write1
|
|
|
|
|
[ pane-current stream-write1 ] do-pane-stream ;
|
|
|
|
|
|
|
|
|
|
M: pane-stream stream-write
|
2006-11-29 15:18:33 -05:00
|
|
|
[ swap string-lines pane-write ] do-pane-stream ;
|
2006-10-04 17:33:02 -04:00
|
|
|
|
|
|
|
|
M: pane-stream stream-format
|
2006-11-29 15:18:33 -05:00
|
|
|
[ rot string-lines pane-format ] do-pane-stream ;
|
2006-10-04 17:33:02 -04:00
|
|
|
|
|
|
|
|
M: pane-stream stream-close drop ;
|
|
|
|
|
|
2006-10-04 21:33:09 -04:00
|
|
|
M: pane-stream stream-flush drop ;
|
2006-10-04 17:33:02 -04:00
|
|
|
|
|
|
|
|
M: pane-stream with-stream-style (with-stream-style) ;
|
|
|
|
|
|
2006-07-22 05:11:19 -04:00
|
|
|
GENERIC: write-gadget ( gadget stream -- )
|
|
|
|
|
|
2006-10-04 17:33:02 -04:00
|
|
|
M: pane-stream write-gadget
|
2006-10-04 21:33:09 -04:00
|
|
|
pane-stream-pane pane-current add-gadget ;
|
2005-12-17 20:03:41 -05:00
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: duplex-stream write-gadget
|
2006-07-22 05:11:19 -04:00
|
|
|
duplex-stream-out write-gadget ;
|
|
|
|
|
|
2006-06-09 22:17:12 -04:00
|
|
|
: print-gadget ( gadget pane -- )
|
|
|
|
|
tuck write-gadget stream-terpri ;
|
|
|
|
|
|
2005-12-17 20:03:41 -05:00
|
|
|
: gadget. ( gadget -- )
|
2006-06-09 22:17:12 -04:00
|
|
|
stdio get print-gadget ;
|
2005-12-17 20:03:41 -05:00
|
|
|
|
2006-12-13 23:40:56 -05:00
|
|
|
: ?terpri ( stream -- )
|
2006-10-04 17:33:02 -04:00
|
|
|
dup pane-stream-pane pane-current gadget-children empty?
|
2006-01-21 02:37:39 -05:00
|
|
|
[ dup stream-terpri ] unless drop ;
|
|
|
|
|
|
2005-09-25 01:10:02 -04:00
|
|
|
: with-pane ( pane quot -- )
|
2006-11-10 15:45:06 -05:00
|
|
|
over scroll>top
|
2006-10-04 17:33:02 -04:00
|
|
|
over pane-clear >r <pane-stream> r>
|
|
|
|
|
over >r with-stream r> ?terpri ; inline
|
2005-12-17 20:03:41 -05:00
|
|
|
|
|
|
|
|
: make-pane ( quot -- pane )
|
2005-12-19 02:12:40 -05:00
|
|
|
<pane> [ swap with-pane ] keep ; inline
|
2006-06-27 03:26:52 -04:00
|
|
|
|
2006-07-19 19:30:02 -04:00
|
|
|
: <scrolling-pane> ( -- pane )
|
|
|
|
|
<pane> t over set-pane-scrolls? ;
|
|
|
|
|
|
2006-06-27 03:26:52 -04:00
|
|
|
: <pane-control> ( model quot -- pane )
|
|
|
|
|
[ with-pane ] curry <pane> swap <control> ;
|
2006-12-13 23:40:56 -05:00
|
|
|
|
|
|
|
|
! Character styles
|
|
|
|
|
|
|
|
|
|
: apply-style ( style gadget key quot -- style gadget )
|
|
|
|
|
>r pick hash r> when* ; inline
|
|
|
|
|
|
|
|
|
|
: 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 )
|
|
|
|
|
[ font swap hash [ "monospace" ] unless* ] keep
|
|
|
|
|
[ 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 ;
|
|
|
|
|
|
|
|
|
|
: apply-presentation-style ( style gadget -- style gadget )
|
|
|
|
|
presented [ <presentation> ] apply-style ;
|
|
|
|
|
|
|
|
|
|
: <styled-label> ( style text -- gadget )
|
|
|
|
|
<label>
|
|
|
|
|
apply-foreground-style
|
|
|
|
|
apply-background-style
|
|
|
|
|
apply-font-style
|
|
|
|
|
apply-presentation-style
|
|
|
|
|
nip ;
|
|
|
|
|
|
|
|
|
|
! Paragraph styles
|
|
|
|
|
|
|
|
|
|
: apply-wrap-style ( style pane -- style pane )
|
|
|
|
|
wrap-margin [
|
|
|
|
|
2dup <paragraph> swap set-pane-prototype
|
|
|
|
|
<paragraph> over set-pane-current
|
|
|
|
|
] 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 ;
|
|
|
|
|
|
|
|
|
|
: apply-page-color-style ( style gadget -- style gadget )
|
|
|
|
|
page-color [
|
|
|
|
|
<solid> over set-gadget-interior
|
|
|
|
|
] apply-style ;
|
|
|
|
|
|
|
|
|
|
: apply-outliner-style ( style gadget -- style gadget )
|
|
|
|
|
outline [ [ make-pane ] curry <outliner> ] apply-style ;
|
|
|
|
|
|
|
|
|
|
: <styled-paragraph> ( style pane -- gadget )
|
|
|
|
|
apply-wrap-style
|
|
|
|
|
apply-border-width-style
|
|
|
|
|
apply-border-color-style
|
|
|
|
|
apply-page-color-style
|
|
|
|
|
apply-presentation-style
|
|
|
|
|
apply-outliner-style
|
|
|
|
|
nip ;
|
|
|
|
|
|
|
|
|
|
: styled-pane ( quot style -- gadget )
|
|
|
|
|
#! Create a pane, call the quotation to fill it out.
|
|
|
|
|
>r <pane> dup r> swap <styled-paragraph>
|
|
|
|
|
>r swap with-pane r> ; inline
|
|
|
|
|
|
|
|
|
|
: apply-table-gap-style ( style grid -- style grid )
|
|
|
|
|
table-gap [ over set-grid-gap ] apply-style ;
|
|
|
|
|
|
|
|
|
|
: apply-table-border-style ( style grid -- style grid )
|
|
|
|
|
table-border [ <grid-lines> over set-gadget-boundary ]
|
|
|
|
|
apply-style ;
|
|
|
|
|
|
|
|
|
|
: styled-grid ( style grid -- grid )
|
|
|
|
|
<grid>
|
|
|
|
|
apply-table-gap-style
|
|
|
|
|
apply-table-border-style
|
|
|
|
|
nip ;
|
|
|
|
|
|
|
|
|
|
: <pane-grid> ( quot style grid -- gadget )
|
|
|
|
|
[
|
|
|
|
|
[ pick pick >r >r -rot styled-pane r> r> rot ] map
|
|
|
|
|
] map styled-grid nip ;
|
|
|
|
|
|
|
|
|
|
M: pane-stream with-stream-table
|
|
|
|
|
>r rot <pane-grid> r> print-gadget ;
|
|
|
|
|
|
|
|
|
|
M: pane-stream with-nested-stream
|
|
|
|
|
>r styled-pane r> write-gadget ;
|
|
|
|
|
|
|
|
|
|
! Stream utilities
|
|
|
|
|
M: pack stream-close drop ;
|
|
|
|
|
|
|
|
|
|
M: paragraph stream-close drop ;
|
|
|
|
|
|
|
|
|
|
: gadget-write ( string gadget -- )
|
|
|
|
|
over empty? [
|
|
|
|
|
2drop
|
|
|
|
|
] [
|
|
|
|
|
>r <label> dup text-theme r> add-gadget
|
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
|
|
M: pack stream-write gadget-write ;
|
|
|
|
|
|
|
|
|
|
: gadget-bl ( style stream -- )
|
|
|
|
|
>r " " <styled-label> <word-break-gadget> r> add-gadget ;
|
|
|
|
|
|
|
|
|
|
M: paragraph stream-write
|
|
|
|
|
swap " " split
|
|
|
|
|
[ over gadget-write ] [ H{ } over gadget-bl ] interleave
|
|
|
|
|
drop ;
|
|
|
|
|
|
|
|
|
|
: gadget-write1 ( char gadget -- )
|
|
|
|
|
>r ch>string r> stream-write ;
|
|
|
|
|
|
|
|
|
|
M: pack stream-write1 gadget-write1 ;
|
|
|
|
|
|
|
|
|
|
M: paragraph stream-write1
|
|
|
|
|
over CHAR: \s =
|
|
|
|
|
[ H{ } swap gadget-bl drop ] [ gadget-write1 ] if ;
|
|
|
|
|
|
|
|
|
|
: gadget-format ( string style stream -- )
|
|
|
|
|
pick empty?
|
|
|
|
|
[ 3drop ] [ >r swap <styled-label> r> add-gadget ] if ;
|
|
|
|
|
|
|
|
|
|
M: pack stream-format
|
|
|
|
|
gadget-format ;
|
|
|
|
|
|
|
|
|
|
M: paragraph stream-format
|
|
|
|
|
presented pick hash [
|
|
|
|
|
gadget-format
|
|
|
|
|
] [
|
|
|
|
|
rot " " split
|
|
|
|
|
[ pick pick gadget-format ]
|
|
|
|
|
[ 2dup gadget-bl ] interleave
|
|
|
|
|
2drop
|
|
|
|
|
] if ;
|