Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file lTerm_toplevel_impl.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155openLTerm_geomopenLTerm_keyclasst=LTerm_widget_base_impl.t(* About focus; widgets may specify an optional target widget in each direction.
The focus specification is intepreted in two ways based on can_focus.
can_focus=true
If the currently focussed widget has a focus specification in the required
direction that widget is jumped to. Otherwise a search is performed.
can_focus=false
Widgets with can_focus=false will never be the current focus, however,
they can take part in search for a widget. When we search over such
a widget, if it has an appropriate focus specification then we jump
there.
*)letget_focusxdir=letf=functionNone->`none|Some(x)->`set_focus(x)inmatchdirwith|`left->fx.left|`right->fx.right|`up->fx.up|`down->fx.downletmake_widget_matrixrootdir=let{rows;cols}=LTerm_geom.size_of_rectroot#allocationinletm=Array.make_matrixrowscols`noneinletrecloopwidget=letsetrectwidget=ifwidget<>`nonethenbeginforr=rect.row1torect.row2-1doforc=rect.col1torect.col2-1dom.(r).(c)<-widgetdonedoneendinifwidget#can_focusthenbeginsetwidget#allocation(`can_focuswidget)endelsebeginsetwidget#allocation(get_focuswidget#focusdir)end;List.iterloopwidget#childreninlooproot;mletleftcoord={coordwithcol=predcoord.col}letrightcoord={coordwithcol=succcoord.col}letupcoord={coordwithrow=predcoord.row}letdowncoord={coordwithrow=succcoord.row}letfocus_to(dir,incr_dir)frootfocusedcoord=letget_coordwidget=letrect=widget#allocationin{col=(rect.col1+rect.col2)/2;row=(rect.row1+rect.row2)/2}inmatchget_focusfocused#focusdirwith|`set_focus(widget)->(* If the currently focused widget has a focus specification for
the given direction jump directly to that widget *)Some(widget,get_coordwidget)|`none->(* Otherwise project a line in the appropriate direction until we hit a widget. *)letrect=root#allocationinletm=make_widget_matrixrootdirinletrecloopcoord=ifcoord.row<rect.row1||coord.row>=rect.row2||coord.col<rect.col1||coord.col>=rect.col2thenNoneelsematchm.(coord.row).(coord.col)with|`none->loop(incr_dircoord)|`can_focuswidgetwhenwidget=focused->loop(incr_dircoord)|`can_focuswidget->letrect=widget#allocationinSome(widget,frectcoord)|`set_focuswidget->(* note; this allows widget=focused, if specified *)Some(widget,get_coordwidget)inloopcoordletavg_colrectcoord={coordwithcol=(rect.col1+rect.col2)/2}letavg_rowrectcoord={coordwithrow=(rect.row1+rect.row2)/2}letfocus_left(* root focused coord *)=focus_to(`left,left)avg_colletfocus_right(* root focused coord *)=focus_to(`right,right)avg_colletfocus_up(* root focused coord *)=focus_to(`up,up)avg_rowletfocus_down(* root focused coord *)=focus_to(`down,down)avg_rowclasstoplevelfocusedwidget=object(self)inheritt"toplevel"assupervalchildren=[widget]method!children=childrenmethod!drawctxfocused=widget#drawctxfocusedvalmutablecoord={row=0;col=0}(* Coordinates of the cursor inside the screen. *)valmutablepush_layer_handler=Lwt_react.E.never;valmutablepop_layer_handler=Lwt_react.E.never;methodarm_layer_handlers(push_event:tLwt_react.event)(push_handler:t->unit)(pop_event:unitLwt_react.event)(pop_handler:unit->unit)=letopenLwt_reactinpush_layer_handler<-E.mappush_handlerpush_event;pop_layer_handler<-E.mappop_handlerpop_eventmethod!set_allocationrect=super#set_allocationrect;widget#set_allocationrect;letrect=!focused#allocationincoord<-{row=(rect.row1+rect.row2)/2;col=(rect.col1+rect.col2)/2}methodmove_focus_to=function|Some(widget,c)->coord<-c;focused:=widget;self#queue_draw|None->()methodprivatemove_focusdirection=self#move_focus_to@@direction(self:>t)!focusedcoordmethodprivateprocess_arrows=function|LTerm_event.Key{control=false;meta=false;shift=false;code=Left}->self#move_focusfocus_left;true|LTerm_event.Key{control=false;meta=false;shift=false;code=Right}->self#move_focusfocus_right;true|LTerm_event.Key{control=false;meta=false;shift=false;code=Up}->self#move_focusfocus_up;true|LTerm_event.Key{control=false;meta=false;shift=false;code=Down}->self#move_focusfocus_down;true|_->falseinitializerwidget#set_parent(Some(self:>t));self#on_eventself#process_arrowsend