2014-02-14 08:05:04 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
|
|
|
* Copyright (C) 2014 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#include <dialog_choose_component.h>
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <component_tree_search_container.h>
|
|
|
|
#include <sch_base_frame.h>
|
|
|
|
|
2014-02-14 17:16:59 +00:00
|
|
|
// Tree navigation helpers.
|
|
|
|
static wxTreeItemId GetPrevItem( const wxTreeCtrl& tree, const wxTreeItemId& item );
|
|
|
|
static wxTreeItemId GetNextItem( const wxTreeCtrl& tree, const wxTreeItemId& item );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-09-26 10:35:11 +00:00
|
|
|
DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle,
|
2014-11-19 14:22:47 +00:00
|
|
|
COMPONENT_TREE_SEARCH_CONTAINER* const aContainer,
|
2014-02-18 21:41:27 +00:00
|
|
|
int aDeMorganConvert )
|
2014-11-19 14:22:47 +00:00
|
|
|
: DIALOG_CHOOSE_COMPONENT_BASE( aParent, wxID_ANY, aTitle ), m_search_container( aContainer )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-09-26 10:35:11 +00:00
|
|
|
m_parent = aParent;
|
2014-11-19 14:22:47 +00:00
|
|
|
m_deMorganConvert = aDeMorganConvert >= 0 ? aDeMorganConvert : 0;
|
|
|
|
m_external_browser_requested = false;
|
|
|
|
m_received_doubleclick_in_tree = false;
|
2014-02-14 08:05:04 +00:00
|
|
|
m_search_container->SetTree( m_libraryComponentTree );
|
|
|
|
m_searchBox->SetFocus();
|
|
|
|
m_componentDetails->SetEditable( false );
|
2016-03-22 18:53:50 +00:00
|
|
|
m_componentView->SetLayoutDirection( wxLayout_LeftToRight );
|
2014-02-27 08:05:28 +00:00
|
|
|
|
2014-02-26 14:06:24 +00:00
|
|
|
m_libraryComponentTree->ScrollTo( m_libraryComponentTree->GetFocusedItem() );
|
2014-02-22 12:39:59 +00:00
|
|
|
|
|
|
|
// The tree showing libs and component uses a fixed font,
|
|
|
|
// because we want controle the position of some info when drawing the
|
|
|
|
// tree. Using tabs does not work very well (does not work on Windows)
|
|
|
|
wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
|
|
|
|
m_libraryComponentTree->SetFont( wxFont( font.GetPointSize(),
|
|
|
|
wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
|
2014-11-19 14:22:47 +00:00
|
|
|
|
2015-03-30 19:34:41 +00:00
|
|
|
// We have to call SetSizeHints to fix the minimal size of the dialog
|
|
|
|
// and its widgets.
|
|
|
|
// this line also fixes an issue on Linux Ubuntu using Unity (dialog not shown).
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
2014-11-19 14:22:47 +00:00
|
|
|
Centre();
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-24 10:52:08 +00:00
|
|
|
DIALOG_CHOOSE_COMPONENT::~DIALOG_CHOOSE_COMPONENT()
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-02-24 10:52:08 +00:00
|
|
|
m_search_container->SetTree( NULL );
|
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2014-02-24 10:52:08 +00:00
|
|
|
LIB_ALIAS* DIALOG_CHOOSE_COMPONENT::GetSelectedAlias( int* aUnit ) const
|
|
|
|
{
|
|
|
|
return m_search_container->GetSelectedAlias( aUnit );
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnSearchBoxChange( wxCommandEvent& aEvent )
|
|
|
|
{
|
2014-10-09 00:49:29 +00:00
|
|
|
m_search_container->UpdateSearchTerm( m_searchBox->GetLineText( 0 ) );
|
2014-02-14 08:05:04 +00:00
|
|
|
updateSelection();
|
2015-02-14 12:43:11 +00:00
|
|
|
|
|
|
|
// On Windows, but not on Linux, the focus is given to
|
|
|
|
// the m_libraryComponentTree, after modificatuons.
|
|
|
|
// We want the focus for m_searchBox.
|
|
|
|
//
|
|
|
|
// We cannot call SetFocus on Linux because it changes the current text selection
|
|
|
|
// and the text edit cursor position.
|
|
|
|
#ifdef __WINDOWS__
|
2014-07-28 09:24:15 +00:00
|
|
|
m_searchBox->SetFocus();
|
2015-02-14 12:43:11 +00:00
|
|
|
#endif
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnSearchBoxEnter( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
EndModal( wxID_OK ); // We are done.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::selectIfValid( const wxTreeItemId& aTreeId )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-02-18 21:41:27 +00:00
|
|
|
if( aTreeId.IsOk() && aTreeId != m_libraryComponentTree->GetRootItem() )
|
2014-02-14 08:05:04 +00:00
|
|
|
m_libraryComponentTree->SelectItem( aTreeId );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnInterceptSearchBoxKey( wxKeyEvent& aKeyStroke )
|
|
|
|
{
|
2014-02-18 21:41:27 +00:00
|
|
|
// Cursor up/down and partiallyi cursor are use to do tree navigation operations.
|
|
|
|
// This is done by intercepting some navigational keystrokes that normally would go to
|
|
|
|
// the text search box (which has the focus by default). That way, we are mostly keyboard
|
|
|
|
// operable.
|
|
|
|
// (If the tree has the focus, it can handle that by itself).
|
2014-02-14 08:05:04 +00:00
|
|
|
const wxTreeItemId sel = m_libraryComponentTree->GetSelection();
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
switch( aKeyStroke.GetKeyCode() )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
|
|
|
case WXK_UP:
|
2014-02-18 21:41:27 +00:00
|
|
|
selectIfValid( GetPrevItem( *m_libraryComponentTree, sel ) );
|
2014-02-14 08:05:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_DOWN:
|
2014-02-18 21:41:27 +00:00
|
|
|
selectIfValid( GetNextItem( *m_libraryComponentTree, sel ) );
|
|
|
|
break;
|
|
|
|
|
2014-10-09 00:49:29 +00:00
|
|
|
// The following keys we can only hijack if they are not needed by the textbox itself.
|
2014-02-18 21:41:27 +00:00
|
|
|
|
|
|
|
case WXK_LEFT:
|
|
|
|
if( m_searchBox->GetInsertionPoint() == 0 )
|
|
|
|
m_libraryComponentTree->Collapse( sel );
|
|
|
|
else
|
|
|
|
aKeyStroke.Skip(); // Use for original purpose: move cursor.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_RIGHT:
|
|
|
|
if( m_searchBox->GetInsertionPoint() >= (long) m_searchBox->GetLineText( 0 ).length() )
|
|
|
|
m_libraryComponentTree->Expand( sel );
|
|
|
|
else
|
|
|
|
aKeyStroke.Skip(); // Use for original purpose: move cursor.
|
2014-02-14 08:05:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-02-18 21:41:27 +00:00
|
|
|
aKeyStroke.Skip(); // Any other key: pass on to search box directly.
|
2014-02-14 08:05:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnTreeSelect( wxTreeEvent& aEvent )
|
|
|
|
{
|
|
|
|
updateSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-24 01:27:07 +00:00
|
|
|
// Test strategy for OnDoubleClickTreeActivation()/OnTreeMouseUp() work around wxWidgets bug:
|
|
|
|
// - search for an item.
|
|
|
|
// - use the mouse to double-click on an item in the tree.
|
|
|
|
// -> The dialog should close, and the component should _not_ be immediately placed
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnDoubleClickTreeActivation( wxTreeEvent& aEvent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-02-18 21:41:27 +00:00
|
|
|
if( !updateSelection() )
|
2014-02-14 08:05:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Ok, got selection. We don't just end the modal dialog here, but
|
|
|
|
// wait for the MouseUp event to occur. Otherwise something (broken?)
|
|
|
|
// happens: the dialog will close and will deliver the 'MouseUp' event
|
|
|
|
// to the eeschema canvas, that will immediately place the component.
|
|
|
|
m_received_doubleclick_in_tree = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnTreeMouseUp( wxMouseEvent& aMouseEvent )
|
|
|
|
{
|
2014-02-18 21:41:27 +00:00
|
|
|
if( m_received_doubleclick_in_tree )
|
2014-02-14 08:05:04 +00:00
|
|
|
EndModal( wxID_OK ); // We are done (see OnDoubleClickTreeSelect)
|
|
|
|
else
|
|
|
|
aMouseEvent.Skip(); // Let upstream handle it.
|
|
|
|
}
|
|
|
|
|
2014-02-24 01:27:07 +00:00
|
|
|
// Test strategy to see if OnInterceptTreeEnter() works:
|
|
|
|
// - search for an item.
|
|
|
|
// - click into the tree once to set focus on tree; navigate. Press 'Enter'
|
|
|
|
// -> The dialog should close and the component be available to place.
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnInterceptTreeEnter( wxKeyEvent& aEvent )
|
|
|
|
{
|
|
|
|
// We have to do some special handling for double-click on a tree-item because
|
|
|
|
// of some superfluous event delivery bug in wxWidgets (see OnDoubleClickTreeActivation()).
|
|
|
|
// In tree-activation, we assume we got a double-click and need to take special precaution
|
|
|
|
// that the mouse-up event is not delivered to the window one level up by going through
|
|
|
|
// a state-sequence OnDoubleClickTreeActivation() -> OnTreeMouseUp().
|
|
|
|
|
|
|
|
// Pressing 'Enter' within a tree will also call OnDoubleClickTreeActivation(),
|
|
|
|
// but since this is not due to the double-click and we have no way of knowing that it is
|
|
|
|
// not, we need to intercept the 'Enter' key before that to know that it is time to exit.
|
2014-02-24 10:52:08 +00:00
|
|
|
if( aEvent.GetKeyCode() == WXK_RETURN )
|
2014-02-24 01:27:07 +00:00
|
|
|
EndModal( wxID_OK ); // Dialog is done.
|
|
|
|
else
|
|
|
|
aEvent.Skip(); // Let tree handle that key for navigation.
|
|
|
|
}
|
|
|
|
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnStartComponentBrowser( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_external_browser_requested = true;
|
|
|
|
EndModal( wxID_OK ); // We are done.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
bool DIALOG_CHOOSE_COMPONENT::updateSelection()
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-02-18 21:41:27 +00:00
|
|
|
int unit = 0;
|
|
|
|
LIB_ALIAS* selection = m_search_container->GetSelectedAlias( &unit );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-19 16:44:48 +00:00
|
|
|
m_componentView->Refresh();
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
m_componentDetails->Clear();
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
if( selection == NULL )
|
|
|
|
return false;
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
m_componentDetails->Freeze();
|
2014-02-14 08:05:04 +00:00
|
|
|
wxFont font_normal = m_componentDetails->GetFont();
|
|
|
|
wxFont font_bold = m_componentDetails->GetFont();
|
|
|
|
font_bold.SetWeight( wxFONTWEIGHT_BOLD );
|
|
|
|
|
|
|
|
wxTextAttr headline_attribute;
|
2014-10-09 00:49:29 +00:00
|
|
|
headline_attribute.SetFont( font_bold );
|
2014-02-14 08:05:04 +00:00
|
|
|
wxTextAttr text_attribute;
|
2014-10-09 00:49:29 +00:00
|
|
|
text_attribute.SetFont( font_normal );
|
|
|
|
|
|
|
|
const wxString name = selection->GetName();
|
|
|
|
|
|
|
|
if ( !name.empty() )
|
|
|
|
{
|
|
|
|
m_componentDetails->SetDefaultStyle( headline_attribute );
|
|
|
|
m_componentDetails->AppendText( name );
|
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
const wxString description = selection->GetDescription();
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
if( !description.empty() )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-10-09 00:49:29 +00:00
|
|
|
if ( !m_componentDetails->IsEmpty() )
|
|
|
|
m_componentDetails->AppendText( wxT( "\n\n" ) );
|
|
|
|
|
2014-02-14 08:05:04 +00:00
|
|
|
m_componentDetails->SetDefaultStyle( headline_attribute );
|
2014-10-09 00:49:29 +00:00
|
|
|
m_componentDetails->AppendText( _( "Description\n" ) );
|
2014-02-14 08:05:04 +00:00
|
|
|
m_componentDetails->SetDefaultStyle( text_attribute );
|
|
|
|
m_componentDetails->AppendText( description );
|
|
|
|
}
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
const wxString keywords = selection->GetKeyWords();
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
if( !keywords.empty() )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-10-09 00:49:29 +00:00
|
|
|
if ( !m_componentDetails->IsEmpty() )
|
|
|
|
m_componentDetails->AppendText( wxT( "\n\n" ) );
|
|
|
|
|
2014-02-14 08:05:04 +00:00
|
|
|
m_componentDetails->SetDefaultStyle( headline_attribute );
|
2014-10-09 00:49:29 +00:00
|
|
|
m_componentDetails->AppendText( _( "Keywords\n" ) );
|
2014-02-14 08:05:04 +00:00
|
|
|
m_componentDetails->SetDefaultStyle( text_attribute );
|
|
|
|
m_componentDetails->AppendText( keywords );
|
|
|
|
}
|
|
|
|
|
2014-10-09 00:49:29 +00:00
|
|
|
if ( !selection->IsRoot() )
|
|
|
|
{
|
|
|
|
LIB_PART* root_part = selection->GetPart();
|
|
|
|
const wxString root_component_name( root_part ? root_part->GetName() : _( "Unknown" ) );
|
|
|
|
|
|
|
|
if ( !m_componentDetails->IsEmpty() )
|
|
|
|
m_componentDetails->AppendText( wxT( "\n\n" ) );
|
|
|
|
|
|
|
|
m_componentDetails->SetDefaultStyle( headline_attribute );
|
|
|
|
m_componentDetails->AppendText( _( "Alias of " ) );
|
|
|
|
m_componentDetails->SetDefaultStyle( text_attribute );
|
|
|
|
m_componentDetails->AppendText( root_component_name );
|
|
|
|
}
|
|
|
|
|
2014-02-14 08:05:04 +00:00
|
|
|
m_componentDetails->SetInsertionPoint( 0 ); // scroll up.
|
2014-02-18 21:41:27 +00:00
|
|
|
m_componentDetails->Thaw();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnHandlePreviewRepaint( wxPaintEvent& aRepaintEvent )
|
|
|
|
{
|
|
|
|
int unit = 0;
|
2014-10-09 00:49:29 +00:00
|
|
|
LIB_ALIAS* selection = m_search_container->GetSelectedAlias( &unit );
|
|
|
|
LIB_PART* part = selection ? selection->GetPart() : NULL;
|
|
|
|
|
|
|
|
// Don't draw anything (not even the background) if we don't have
|
|
|
|
// a part to show
|
|
|
|
if( !part )
|
|
|
|
return;
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2014-10-09 00:49:29 +00:00
|
|
|
if( selection->IsRoot() )
|
|
|
|
{
|
|
|
|
// just show the part directly
|
|
|
|
renderPreview( part, unit );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// switch out the name temporarily for the alias name
|
|
|
|
wxString tmp( part->GetName() );
|
|
|
|
part->SetName( selection->GetName() );
|
|
|
|
|
|
|
|
renderPreview( part, unit );
|
|
|
|
|
|
|
|
part->SetName( tmp );
|
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
|
|
|
|
// Render the preview in our m_componentView. If this gets more complicated, we should
|
|
|
|
// probably have a derived class from wxPanel; but this keeps things local.
|
2014-10-09 00:49:29 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_PART* aComponent, int aUnit )
|
2014-02-18 21:41:27 +00:00
|
|
|
{
|
|
|
|
wxPaintDC dc( m_componentView );
|
2015-08-30 14:46:34 +00:00
|
|
|
|
|
|
|
const wxSize dc_size = dc.GetSize();
|
|
|
|
|
|
|
|
// Avoid rendering when either dimension is zero
|
|
|
|
if( dc_size.x == 0 || dc_size.y == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
GRResetPenAndBrush( &dc );
|
|
|
|
|
2014-09-26 10:35:11 +00:00
|
|
|
EDA_COLOR_T bgcolor = m_parent->GetDrawBgColor();
|
2014-10-09 00:49:29 +00:00
|
|
|
|
2014-09-26 10:35:11 +00:00
|
|
|
dc.SetBackground( bgcolor == BLACK ? *wxBLACK_BRUSH : *wxWHITE_BRUSH );
|
2014-02-18 21:41:27 +00:00
|
|
|
dc.Clear();
|
|
|
|
|
|
|
|
if( aComponent == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aUnit <= 0 )
|
|
|
|
aUnit = 1;
|
|
|
|
|
|
|
|
dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
|
|
|
|
|
|
|
|
// Find joint bounding box for everything we are about to draw.
|
2014-02-19 16:44:48 +00:00
|
|
|
EDA_RECT bBox = aComponent->GetBoundingBox( aUnit, m_deMorganConvert );
|
2014-02-18 21:41:27 +00:00
|
|
|
const double xscale = (double) dc_size.x / bBox.GetWidth();
|
|
|
|
const double yscale = (double) dc_size.y / bBox.GetHeight();
|
|
|
|
const double scale = std::min( xscale, yscale ) * 0.85;
|
|
|
|
|
|
|
|
dc.SetUserScale( scale, scale );
|
|
|
|
|
2015-06-26 13:41:56 +00:00
|
|
|
wxPoint offset = -bBox.Centre();
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2015-03-30 15:23:31 +00:00
|
|
|
|
2014-02-19 16:44:48 +00:00
|
|
|
aComponent->Draw( NULL, &dc, offset, aUnit, m_deMorganConvert, GR_COPY,
|
|
|
|
UNSPECIFIED_COLOR, DefaultTransform, true, true, false );
|
2014-02-18 21:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-14 17:16:59 +00:00
|
|
|
static wxTreeItemId GetPrevItem( const wxTreeCtrl& tree, const wxTreeItemId& item )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-02-14 17:16:59 +00:00
|
|
|
wxTreeItemId prevItem = tree.GetPrevSibling( item );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
if( !prevItem.IsOk() )
|
|
|
|
{
|
|
|
|
prevItem = tree.GetItemParent( item );
|
|
|
|
}
|
|
|
|
else if( tree.IsExpanded( prevItem ) )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-02-18 21:41:27 +00:00
|
|
|
prevItem = tree.GetLastChild( prevItem );
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 17:16:59 +00:00
|
|
|
return prevItem;
|
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2014-02-14 17:16:59 +00:00
|
|
|
static wxTreeItemId GetNextItem( const wxTreeCtrl& tree, const wxTreeItemId& item )
|
|
|
|
{
|
2014-02-18 21:41:27 +00:00
|
|
|
wxTreeItemId nextItem;
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2015-08-06 09:17:23 +00:00
|
|
|
if( !item.IsOk() )
|
|
|
|
return nextItem; // item is not valid: return a not valid wxTreeItemId
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
if( tree.IsExpanded( item ) )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2014-02-14 17:16:59 +00:00
|
|
|
wxTreeItemIdValue dummy;
|
2014-02-18 21:41:27 +00:00
|
|
|
nextItem = tree.GetFirstChild( item, dummy );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-06 09:17:23 +00:00
|
|
|
wxTreeItemId root_cell= tree.GetRootItem();
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
// Walk up levels until we find one that has a next sibling.
|
|
|
|
for ( wxTreeItemId walk = item; walk.IsOk(); walk = tree.GetItemParent( walk ) )
|
|
|
|
{
|
2015-08-06 09:17:23 +00:00
|
|
|
if( walk == root_cell ) // the root cell (not displayed) is reached
|
|
|
|
break; // Exit (calling GetNextSibling( root_cell ) crashes.
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
nextItem = tree.GetNextSibling( walk );
|
2014-10-09 00:49:29 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
if( nextItem.IsOk() )
|
|
|
|
break;
|
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 17:16:59 +00:00
|
|
|
return nextItem;
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|