` Metadocument shell ` !! MetaDoc (Title @MD_Code): [Doc] ` constructor ` = { Doc = metadoc!!create_metadoc (Title); metadoc!!with_metadoc (Doc, ^MD_Code); } ` destructor ` ~ { metadoc!!destroy_metadoc (Doc); Doc = () } ; ` TODO: fix bug in virtuals destruction! ` oShowNodes = 1; oShowBaselines = 2; HelpText = " Keyboard: [Left/Right]: scroll left/right. [Up]/[Down]: scroll up/down. [PgUp]/[PgDn]: scroll page up/page down. [Home]/[End]: scroll to top/to bottom. [F2]: show nodes off/on. [F3]: show baselines off/on. Drag mouse with left button pressed to scroll document. "; ` Metadocument view widget ` !! [Widget] MetaDocView (MetaDoc) : [DocCore DocHgt DocWdt StepX StepY OffX OffY Options] = { DocCore = MetaDoc!!MetaDoc.Doc; OffX = OffY = 0; [StepX StepY] = [16 16]; Options = 0; unless (#Title):: (Title = metadoc!!get_meta_name (DocCore)); } { ! do_open = metadoc!! { with_widget (measure_metadoc (DocCore)); if (0):: dump_metadoc (DocCore); create_metaview (DocCore, self (!.)); [DocWdt DocHgt] = format_metaview (DocCore, self (!.), [Width Height], 0); }, ! #on_open = do_open (), ! do_paint (L_T R_B) = graphics!! metadoc!! { fill_color (White ()):: fill (L_T, R_B); draw_metaview (DocCore, self (!.), [OffX OffY], [0 0], [Width Height], Options); if (Options & oShowNodes):: ` show location nodes ` fill_disable (1):: plot_color (Red ()):: metaview_loc_loop (DocCore, self (!.), [OffX OffY], [0 0], [Width Height], !(x y) = (oval ((x-3, y-3), (x+3, y+3)))); ` show baselines ` if (Options & oShowBaselines):: plot_color (Blue ()):: metaview_base_loop (DocCore, self (!.), [OffX OffY], [0 0], [Width Height], !(y) = (line ([0 y], [Width y]))); }, ! do_resize = { [DocWdt DocHgt] = metadoc!!format_metaview (DocCore, self (!.), [Width Height], 0); with_widget (do_paint ([0 0], [Width Height])); }, ! #on_resize = do_resize (), ! #on_paint (L_T R_B) = do_paint (L_T, R_B), ! do_close = metadoc!!delete_metaview (DocCore, self (!.)), ! #on_close = do_close (), ! bound (Val Min Max) = Min ?> Val ?< Max, ! offset (RelX RelY) : [NewX NewY _RelX _RelY] = { NewY = bound (OffY + RelY, Height - DocHgt, 0); NewX = 0; ` TODO... ` [_RelX _RelY] = (NewX - OffX, NewY - OffY); (_RelX || _RelY) ? { [OffX OffY] = [NewX NewY]; with_widget (on_paint ([0 0], [Width Height])); }: ; _RelX == RelX && _RelY == RelY }, ! #on_key (action key) : [check] = action > 0 ? { check = key == KB_Up? offset (0, StepY): key == KB_Down? offset (0, - StepY): key == KB_Left? offset (StepX, 0): key == KB_Right? offset (- StepX, 0): key == KB_PgUp? offset (0, Height) : key == KB_PgDn? offset (0, - Height) : ; (#check) ? (check ~? alert_beep () : ) : { check = key == KB_Home? (OffY = 0) : key == KB_End? (OffY = Height - DocHgt) : key == KB_F1? { alert_box ("Help", HelpText); } : key == KB_F2? (Options =~: 1) : key == KB_F3? (Options =~: 2) : ; (#check) ? with_widget (on_paint ([0 0], [Width Height])) : ; } } : , ` -- on_key ` ! #on_mouse_move (State From To) = if ((State & (MB_Left << 16)) && #From && #To):: offset (To[0] - From[0], To[1] - From[1]) ` -- on_mouse_move ` }; ` Standart wrappers: ` ` String of text... ` !_ (s) = graphics!!text (s); ` Bold wrapper ` !B (@_) = graphics!!font_weight (1)::(^_); ` Italic wrapper ` !I (@_) = graphics!!font_italic (1)::(^_); ` Underline wrapper ` !U (@_) = graphics!!font_underline (1)::(^_); ` Overstrike wrapper ` !O (@_) = graphics!!font_overstrike (1)::(^_); ` Inverse wrapper ` !V (@_) = graphics!!font_inverse (^_); ` Paragraph enclosure ` !P (@_) = { ^_; _ '\P'; }; ` Font face wrapper ` !FontFace (face @_) = graphics!!font_face (face)::(^_); ` Font size wrapper ` !FontSize (size @_) = graphics!!font_size (size)::(^_); ` Font width wrapper ` !FontWeight (weight @_) = graphics!!font_weight (weight)::(^_); ` Font width wrapper ` !FontWidth (width @_) = graphics!!font_width (width)::(^_); ` Font foreground color wrapper ` !FontFgColor (fgcolor @_) = graphics!!font_fgcolor (fgcolor)::(^_); ` Font background color wrapper ` !FontBgColor (bgcolor @_) = graphics!!font_bgcolor (bgcolor)::(^_); ` Paragraph default metrics ` !ParaDef (@_) = metadoc!!with_def_format (^_); ` Paragraph alignment ` !LeftAlign (@_) = metadoc!!with_align_left (^_); !RightAlign (@_) = metadoc!!with_align_right (^_); !CenterAlign (@_) = metadoc!!with_align_center (^_); !FullAlign (@_) = metadoc!!with_align_full (^_); ` Paragraph indentation (horizontal) ` ! ParaIndents (Indents @_) = metadoc!!with_hort_ext (Indents[0], Indents[1], Indents[2], ^_); ` Paragraph insets (vertical) ` ! ParaInsets (Insets @_) = metadoc!!with_vert_int (Insets[0], Insets[1], Insets[2], ^_); ` Paragraph outsets (vertical) ` ! ParaOutsets (Outsets @_) = metadoc!!with_vert_ext (Outsets[0], Outsets[1], ^_);