flu_tree_browser.cpp

来自「ncbi源码」· C++ 代码 · 共 2,583 行 · 第 1/5 页

CPP
2,583
字号
	  return true;	}      else	return false;    }  if( where==MOVE_AFTER && n2->is_branch() && n2->open() )    {      // can't move inside a branch if within the same group, unless the first node is dragged       // from outside the tree (in which case n1 is NULL)      if( sameGroup && n1 )	{	  if( n2->_children.size() > 0 )	    return false;	}      else if( n2->_children.size() > 0 )	{	  where = MOVE_BEFORE;	  n2 = n2->_children.child(0);	}      else	where = MOVE_INSIDE;    }  if( where==MOVE_INSIDE )    {      if( !n2->droppable() )	return false;    }  else if( n2->parent() )    if( !n2->parent()->droppable() )      return false;  return true;}int Flu_Tree_Browser :: Node :: recurse( RData &rdata, int type, int event ){  int i;  if( type == COUNT_SELECTED )    {      if( is_leaf() )	return (int)CHECK(SELECTED);      else	{	  int total = (int)CHECK(SELECTED);	  for( i = 0; i < _children.size(); i++ )	    total += _children.child(i)->recurse( rdata, type, event );	  return total;	}    }  // see if this entry is even visible  if( rdata.y > rdata.browserY+rdata.browserH )    {      if( type == DRAW )	return 1;      else if( type == HANDLE )	return 0;    }  int which = open();  bool skipEntry = ( is_root() && !rdata.showRoot ) || ( is_leaf() && !rdata.showLeaves ) || ( is_branch() && !rdata.showBranches );  bool skipCollapser = is_root() && rdata.showRoot && ( CHECK(ALWAYS_OPEN) || rdata.allBranchesAlwaysOpen );  // find the size of the entry label  if( (type == MEASURE) || (type == MEASURE_THIS_OPEN) )    {      if( CHECK(SHOW_LABEL) )	{	  int W = 0, H;	  fl_font( textFont, textSize );	  fl_measure( text.c_str(), W, H );	  W += 4; H += 4;  // hack - it looks better	  textW = W;	  textH = H;	}      else	{	  textW = textH = 0;	}      // remember vertically where this node is w.r.t the browser      currentY = rdata.y;      currentH = textH;      // find the total size of the entry, depending on if there's a widget      if( _widget )	currentH = MAX( _widget->w->h(), currentH );      // find the total height of this entry by taking the max height of the entry and icons      if( is_leaf() )	{	  if( lIcon )	    currentH = MAX( currentH, lIcon->h() );	}      else	{	  currentH = MAX( currentH, cIcon[which]->h() );	  if( bIcon[which] )	    currentH = MAX( currentH, bIcon[which]->h() );	}    }  bool skipAhead = (rdata.y + currentH) < rdata.browserY;  // process the entry  switch( type )    {    case DRAW:      {	if( skipEntry || skipAhead ) break;	draw( rdata, false );	// draw any vertical connectors connecting our aunts, great aunts, etc.,	if( rdata.showBranches )	  {	    int d = depth()-1;	    for( i = 0; i < rdata.branchConnectors.size(); i++ )	      {		if( i != d )		  {		    fl_color( rdata.lineColor );		    fl_line_style( rdata.lineStyle, rdata.lineWidth );		    fl_line( rdata.branchConnectors[i], rdata.y, rdata.branchConnectors[i], rdata.y+currentH );		    fl_line_style( 0 );		  }	      }	  }	rdata.shadedIndex = 1 - rdata.shadedIndex;  // toggle the even/odd entry for shading      }      break;    case MEASURE:      if( is_leaf() )	CLEAR( SOME_VISIBLE_CHILDREN );      else	{	  // find out whether the branch has any children that could be visible	  bool someVisibleChildren = rdata.showLeaves && ( _children.size() > 0 );	  for( i = 0; i < _children.size(); i++ )	    {	      if( _children.child(i)->is_branch() )		{		  someVisibleChildren = true;		  break;		}	    }	  SET( SOME_VISIBLE_CHILDREN, someVisibleChildren );	}    case MEASURE_THIS_OPEN:      if( skipEntry ) break;      draw( rdata, true );      break;    case HANDLE:      {	if( skipEntry || skipAhead || !CHECK(ACTIVE) ) break;	if( event != FL_DRAG && event != FL_NO_EVENT )	  rdata.justOpenedClosed = false;	// if we are trying to select all entries between 2 widgets due to a shift-select...	if( rdata.shiftSelect )	  {	    if( (rdata.hilighted == this) || (rdata.grabbed == this) )	      {		if( !rdata.shiftSelectAll )		  {		    rdata.shiftSelectAll = true;		    select( true );		    if( is_branch() && rdata.openOnSelect )		      {			open( true );		      }		  }		else		  {		    rdata.shiftSelect = false;		    rdata.shiftSelectAll = false;		    rdata.grabbed = 0;		    select( true );		    if( is_branch() && rdata.openOnSelect )		      {			open( true );		      }		  }	      }	    else if( rdata.shiftSelectAll )	      {		select( true );		if( is_branch() && rdata.openOnSelect )		  {		    open( true );		  }	      }	    break;	  }	// check for the keyboard event	if( event == FL_KEYDOWN )	  {	    // check for the spacebar selecting this entry	    if( Fl::event_key() == ' ' && rdata.hilighted == this )	      {		if( Fl::event_state(FL_CTRL) )		  select( !CHECK(SELECTED) );		else		  {		    rdata.root->unselect_all( this );		    select( true );		  }		if( is_branch() && rdata.openOnSelect )		  {		    open( true );		  }		return 1;			      }	    // check for the enter key opening/closing this entry	    else if( (Fl::event_key() == FL_Enter) && (rdata.hilighted == this) )	      {		open( !open() );		return 1;	      }	    // check for the left/right cursor keys opening/closing this entry	    else if( (Fl::event_key() == FL_Left) && (rdata.hilighted == this) )	      {		open( false );		return 1;	      }	    else if( (Fl::event_key() == FL_Right) && (rdata.hilighted == this) )	      {		open( true );		return 1;	      }	  }	// check for the "up" cursor key moving the hilighted entry	if( rdata.delta == -1 && rdata.hilighted == this && rdata.previous != NULL )	  {	    tree->set_hilighted( rdata.previous );	    rdata.delta = 0;	    return 1;	  }	// check for the "down" cursor key moving the hilighted entry	if( rdata.delta == 1 && rdata.hilighted == rdata.previous )	  {	    tree->set_hilighted( this );	    rdata.delta = 0;	    return 1;	  }	rdata.previous = this;	// the event is not ours to use	//if( _widget && !rdata.dragging )	//if( Fl::event_inside( _widget->w ) )	//  return 2;	bool inExpander = false;	if( is_branch() )	  {	    int which = open();	    if( _parent==0 )	      inExpander = Fl::event_inside( rdata.x, rdata.y+(currentH>>1)-(cIcon[which]->h()>>1),					     cIcon[which]->w(), cIcon[which]->h() );	    else	      inExpander = Fl::event_inside( rdata.x+(rdata.branchIconW>>1)-(cIcon[which]->w()>>1),					     rdata.y+(currentH>>1)-(cIcon[which]->h()>>1),					     cIcon[which]->w(), cIcon[which]->h() );	  }	if( event == FL_PUSH )	  {		    // check for expand/collapse	    if( Fl::event_button() == FL_LEFT_MOUSE && inExpander )	      {		/*		if( is_branch() )		  {		    bool c = false;		    int which = open();		    if( _parent==0 )		      {			c = Fl::event_inside( rdata.x, rdata.y+(currentH>>1)-(cIcon[which]->h()>>1),					      cIcon[which]->w(), cIcon[which]->h() );		      }		    else		      c = Fl::event_inside( rdata.x+(rdata.branchIconW>>1)-(cIcon[which]->w()>>1),					    rdata.y+(currentH>>1)-(cIcon[which]->h()>>1),					    cIcon[which]->w(), cIcon[which]->h() );		    if( inExpander )		    {*/			open( !open() );			rdata.dragging = false;			rdata.dragNode = 0;			return 1;			//}			//}	      }	  }	if( event == FL_DRAG && rdata.justOpenedClosed )	  return 0;	// if no selections, return	if( rdata.selectionMode == FLU_NO_SELECT )	  break;	// if the event is not inside us, return	if( !Fl::event_inside( rdata.browserX, rdata.y, rdata.browserW, currentH ) )	  break;#ifdef USE_FLU_DND	// check for grabbing of a node for DND	if( event == FL_DRAG && rdata.selectionDragMode == FLU_DRAG_TO_MOVE && !is_root() && rdata.grabbed &&	    //rdata.insertionMode!=FLU_INSERT_SORTED && rdata.insertionMode!=FLU_INSERT_SORTED_REVERSE &&	    !tree->dnd_is_dragging() && !rdata.justOpenedClosed && CHECK(MOVABLE) )	  {	    tree->dnd_grab( this, "Flu_Tree_Browser" );	    return 1;	  }	// dragging to move a node	if( event == FL_DND_DRAG )	  {	    rdata.dragNode = this; // remember which node to move the grabbed node before/after	    if( is_root() )	      {		rdata.dragWhere = MOVE_AFTER;		rdata.dragPos = rdata.y + currentH;	      }	    else	      {		// if this is a leaf or an open branch, then can only move before or after		// otherwise can move inside		if( is_branch() && !open() )		  {		    int t = MAX( currentH / 3, 1 );		    if( (Fl::event_y()-rdata.y) <= t )		      rdata.dragWhere = MOVE_BEFORE;		    else if( (Fl::event_y()-rdata.y) <= (t<<1) )		      rdata.dragWhere = MOVE_INSIDE;		    else		      rdata.dragWhere = MOVE_AFTER;		  }		else		  {		    if( (Fl::event_y()-rdata.y) <= (currentH>>1) )		      rdata.dragWhere = MOVE_BEFORE;		    else		      rdata.dragWhere = MOVE_AFTER;		  }		// where to draw the insertion position?		if( rdata.dragWhere == MOVE_BEFORE || rdata.dragWhere == MOVE_INSIDE )		  rdata.dragPos = rdata.y;		else		  rdata.dragPos = rdata.y + currentH;	      }	    return 1;	  }#endif	// single selection	if( rdata.selectionMode == FLU_SINGLE_SELECT )	  {	    if( event == FL_PUSH )	      {		//rdata.dragging = true;		rdata.grabbed = this;		rdata.root->unselect_all( this );		tree->set_hilighted( this );		if( Fl::event_state(FL_CTRL) )		  select( !CHECK(SELECTED) );		else		  select( true );		if( is_leaf() )		  {		    if( Fl::event_clicks() > 0 )		      {			Fl::event_clicks(0);			do_callback( FLU_DOUBLE_CLICK );		      }		  }		else		  {		    if( Fl::event_clicks() > 0 )		      {			Fl::event_clicks(0);			if( rdata.doubleClickToOpen )			  open( !open() );			else			  do_callback( FLU_DOUBLE_CLICK );		      }		    else if( rdata.openOnSelect )		      {			open( true );		      }		  }		return 1;	      }	    else if( event == FL_DRAG )	      {		rdata.dragging = true;		//if( ( rdata.selectionDragMode == FLU_DRAG_IGNORE || rdata.selectionDragMode == FLU_DRAG_TO_MOVE) && ( tree->insertion_mode() == FLU_INSERT_FRONT || tree->insertion_mode() == FLU_INSERT_BACK ) )		//return 1;		rdata.root->unselect_all( this );		tree->set_hilighted( this );		select( true );		return 1;	      }	    else if( event == FL_RELEASE && rdata.when == FL_WHEN_RELEASE && selected() && !inExpander )	      {		do_callback( FLU_SELECTED );		return 1;	      }	  }	// multiple selection	else if( rdata.selectionMode == FLU_MULTI_SELECT )	  {	    if( event == FL_PUSH )	      {		//rdata.dragging = true;		rdata.grabbed = this;		if( Fl::event_state(FL_CTRL) )		  {		    select( !CHECK(SELECTED) );		    tree->set_hilighted( this );		  }		else if( Fl::event_state(FL_SHIFT) )		  {		    // select everything from the last selected entry to this one		    if( rdata.hilighted == this )		      {			select( true );			if( is_branch() )			  {			    if( Fl::event_clicks() > 0 )			      {				Fl::event_clicks(0);				if( rdata.doubleClickToOpen )				  open( !open() );				else				  do_callback( FLU_DOUBLE_CLICK );			      }			    else if( rdata.openOnSelect )			      {				open( !open() );			      }			  }		      }		    else		      {			rdata.shiftSelectAll = false;			rdata.shiftSelect = true;			rdata.grabbed = this;			rdata.root->recurse( rdata, HANDLE, 0 );			tree->set_hilighted( this );		      }		  }		else		  {		    rdata.root->unselect_all( this );		    select( true );		    if( is_leaf() )		      {			if( Fl::event_clicks() > 0 )			  {			    Fl::event_clicks(0);			    do_callback( FLU_DOUBLE_CLICK );			  }		      }		    else		      {			if( Fl::event_clicks() > 0 )			  {			    Fl::event_clicks(0);			    if( rdata.doubleClickToOpen )			      open( !open() );			    else			      do_callback( FLU_DOUBLE_CLICK );			  }			else if( rdata.openOnSelect )			  {			    open( true );			  }		      }		    tree->set_hilighted( this );		  }		return 1;	      }	    else if( event == FL_DRAG )	      {		rdata.dragging = true;		//if( ( rdata.selectionDragMode == FLU_DRAG_IGNORE || rdata.selectionDragMode == FLU_DRAG_TO_MOVE) && ( tree->insertion_mode() == FLU_INSERT_FRONT || tree->insertion_mode() == FLU_INSERT_BACK ) )		//return 1;		select( true );		tree->set_hilighted( this );		return 1;	      }	    else if( event == FL_RELEASE && rdata.when == FL_WHEN_RELEASE && selected() && !inExpander )	      {		d

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?