/frame superclass /borderS 5 def /borderN 5 def /borderE 5 def /borderW 5 def /addmember { % drawable -- /layout /descendantof 2 index send { //addmember exec } { /addmember @current_layout send } ifelse } def /current_layout_index { % -- int 0 members @current_layout arrayindex not -1 if 1 sub max } def /new_layout { % -- /layout newmember members members length exch dup length array copy exch arraydelete /members exch promote members current_layout_index 2 add 2 index arrayinsert /members exch promote goto_layout } def /goto_layout { % any -- dup truedicttype goto_layout$SwiTch0 exch 2 copy known not { pop /$deFaUlT } if get exec members 1 index arrayindex not -1 if 0 gt { dup @current_layout ne } false ifelse { edit_mode { //nullarray /stop_edit_ctx @edit_ctx Send } if /unmap @current_layout send /@current_layout exch promote /map @current_layout send edit_mode { //nullarray /start_edit_ctx @edit_ctx Send } if } {pop} ifelse } def /goto_layout$SwiTch0 4 dict dup begin /$deFaUlT {find_object} def /integertype { members members length 2 sub 3 -1 roll cvi min 1 add get } def /fixedtype { round goto_layout$SwiTch0 /integertype get exec } def /realtype currentdict /fixedtype get def end def /goto_next_layout { % -- current_layout_index 1 add members length 1 sub mod goto_layout } def /goto_previous_layout { % -- current_layout_index dup 0 le { pop members length 2 } 1 ifelse sub goto_layout } def /goto_first_layout { % -- members 1 get goto_layout } def /goto_last_layout { % -- members members length 1 sub get goto_layout } def /oninit { % -- members length 0 eq { /layout newmember pop /layout newmember pop } if self soften /@window exch promote members 0 get soften /@window_layout exch promote members 1 get soften /@current_layout exch promote members 1 get soften /@first_layout exch promote /map @window_layout send /map @current_layout send //oninit exec } def /Paint { % -- //Paint exec -1 [borderW borderS w borderW sub borderE sub h borderS sub borderN sub] insetstroke aload pop rectpath BG2 setcolor stroke } def /hit { % eventtype -- drawable dup /hit @current_layout send dup null ne { exch pop } { pop /hit @window_layout send dup null eq { pop self } if } ifelse } def /@menu { % -- menu edit_mode {@editmenu} {@windowmenu} ifelse } def /edit_mode false def /start_edit_mode { % -- edit_mode not { /edit_mode true promote //nullarray /start_edit_ctx @edit_ctx Send } if } def /stop_edit_mode { % -- edit_mode { //nullarray /stop_edit_ctx @edit_ctx Send /edit_mode unpromote //nullarray /focus_change @focus Send //nullarray /focus_change self Send } if } def /flip_edit_mode { % -- edit_mode {stop_edit_mode} { start_edit_mode} ifelse } def /set_edit_ctx { % drawable -- @edit_ctx 1 index ne { edit_mode { //nullarray /stop_edit_ctx @edit_ctx Send } if dup @current_layout eq { pop @current_layout /edit_ctx undef } { dup @window_layout eq { pop @current_layout /edit_ctx null } { @current_layout /edit_ctx 3 -1 roll } ifelse put } ifelse edit_mode { //nullarray /start_edit_ctx @edit_ctx Send } if } {pop} ifelse } def /ctx_to_parent { % -- //nullarray /edit_ctx_parent @edit_ctx Send } def /ctx_to_selected { % -- //nullarray /edit_ctx_selected @edit_ctx Send } def /ctx_to_current_layout { % -- @current_layout set_edit_ctx } def /ctx_to_window_layout { % -- @window_layout set_edit_ctx } def /select_click { % -- @freezer null ne {totop} { mouseevent /KeyState get 28536 arraycontains? {flip_edit_mode} { edit_mode { [/edit_select_click] /gexec @edit_ctx Send } { //select_click exec } ifelse } ifelse } ifelse } def /menu_click { % -- @freezer null ne {totop} { edit_mode { self /showmenu @editmenu send } { //menu_click exec } ifelse } ifelse } def /paint { % -- //paint exec edit_mode { [/paint_edit_mode] /gexec @edit_ctx Send } if } def /fix { % -- //fix exec edit_mode { [/paint_edit_mode] /gexec @edit_ctx Send } if } def