1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#include "TMainTree.h"
BEGIN_EVENT_TABLE(TMainTree, wxTreeCtrl)
EVT_TREE_ITEM_RIGHT_CLICK(MAIN_TREE_DUMMY,TMainTree::OnRightClick)
EVT_TREE_SEL_CHANGED(MAIN_TREE_DUMMY,TMainTree::OnEvent)
EVT_MENU(MT_CLOSE,TMainTree::OnCloseChild)
END_EVENT_TABLE()
/** \brief Constructor
*/
TMainTree::TMainTree ( wxSashLayoutWindow *parent , int i )
:wxTreeCtrl ( parent , i )
{
lastChild = NULL ;
}
/** \brief Initialization of the tree; removal of old items, if any
*/
void TMainTree::initme()
{
// Basic stuff
DeleteAllItems () ;
treeroot = AddRoot ( myapp()->frame->project.name ) ;
vectors = AppendItem ( treeroot , txt("vectors") ) ;
fragments = AppendItem ( treeroot , txt("fragments") ) ;
sequences = AppendItem ( treeroot , txt("sequences") ) ;
primers = AppendItem ( treeroot , txt("primers") ) ;
alignments = AppendItem ( treeroot , txt("alignments") ) ;
amino_acids = AppendItem ( treeroot , txt("amino_acids") ) ;
misc = AppendItem ( treeroot , txt("misc_stuff") ) ;
SetFont ( *MYFONT ( MYFONTSIZE , wxSWISS , wxNORMAL , wxNORMAL ) ) ;
EnsureVisible ( vectors ) ;
}
/** \brief Handles right click on an item (context menu)
*/
void TMainTree::OnRightClick ( wxTreeEvent &event )
{
wxPoint pt = event.GetPoint() ;
wxTreeItemId id = event.GetItem () ;
if ( !id.IsOk() ) return ;
TMainTreeItem *d = (TMainTreeItem*) GetItemData ( id ) ;
if ( !d || !d->c ) return ;
lastChild = (ChildBase*) d->c ;
wxMenu *cm = new wxMenu ;
cm->Append ( MT_CLOSE , txt("m_close") ) ;
PopupMenu ( cm , pt ) ;
delete cm ;
}
/** \brief Adds a child to the tree
\param c Pointer to child
\param type Where to add it
*/
void TMainTree::addChild ( ChildBase *c , int type )
{
wxTreeItemId theroot ;
if ( type == TYPE_VECTOR ) theroot = vectors ;
else if ( type == TYPE_FRAGMENT ) theroot = fragments ;
else if ( type == TYPE_SEQUENCE ) theroot = sequences ;
else if ( type == TYPE_PRIMER ) theroot = primers ;
else if ( type == TYPE_ALIGNMENT ) theroot = alignments ;
else if ( type == TYPE_AMINO_ACIDS ) theroot = amino_acids ;
else if ( type == TYPE_MISC ) theroot = misc ;
c->inMainTree = AppendItem ( theroot , c->getName() , -1 ) ;
SetItemData ( c->inMainTree , new TMainTreeItem ( c ) ) ;
EnsureVisible ( c->inMainTree ) ;
// SelectItem ( c->inMainTree ) ;
}
/** \brief Remove child from the tree
*/
void TMainTree::removeChild ( ChildBase *c )
{
if ( !c || !c->inMainTree.IsOk() ) return ;
Delete ( c->inMainTree ) ;
}
/** \brief Event handler (when an item gets the focus, via keyboard or mouse)
*/
void TMainTree::OnEvent ( wxTreeEvent &event )
{
if ( myapp()->frame->isActivating() ) return ;
if ( myapp()->frame->isLocked() ) return ;
wxTreeItemId id = event.GetItem () ;
if ( !id.IsOk() ) return ;
TMainTreeItem *d = (TMainTreeItem*) GetItemData ( id ) ;
if ( !d ) return ;
if ( !d->c ) return ;
d->c->Activate () ;
}
/** \brief Closes the current child
*/
void TMainTree::OnCloseChild ( wxCommandEvent &event )
{
if ( !lastChild ) return ;
if ( lastChild->Close ( FALSE ) ) lastChild = NULL ;
// else wxBell();
}
|