Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
See license in Gwen.h
|
||||
*/
|
||||
|
||||
|
||||
#include "Gwen/Controls/TreeNode.h"
|
||||
#include "Gwen/Controls/TreeControl.h"
|
||||
#include "Gwen/Utility.h"
|
||||
@@ -12,47 +11,46 @@
|
||||
using namespace Gwen;
|
||||
using namespace Gwen::Controls;
|
||||
|
||||
class OpenToggleButton : public Button
|
||||
class OpenToggleButton : public Button
|
||||
{
|
||||
GWEN_CONTROL_INLINE ( OpenToggleButton, Button )
|
||||
GWEN_CONTROL_INLINE(OpenToggleButton, Button)
|
||||
{
|
||||
SetIsToggle( true );
|
||||
SetTabable( false );
|
||||
|
||||
SetIsToggle(true);
|
||||
SetTabable(false);
|
||||
}
|
||||
|
||||
virtual void RenderFocus( Skin::Base* /*skin*/ ) {}
|
||||
virtual void RenderFocus(Skin::Base* /*skin*/) {}
|
||||
|
||||
virtual void Render( Skin::Base* skin )
|
||||
virtual void Render(Skin::Base* skin)
|
||||
{
|
||||
skin->DrawTreeButton( this, GetToggleState() );
|
||||
skin->DrawTreeButton(this, GetToggleState());
|
||||
}
|
||||
};
|
||||
|
||||
const int TreeIndentation = 14;
|
||||
const int BranchLength = 16;
|
||||
|
||||
GWEN_CONTROL_CONSTRUCTOR( TreeNode )
|
||||
GWEN_CONTROL_CONSTRUCTOR(TreeNode)
|
||||
{
|
||||
m_TreeControl = NULL;
|
||||
|
||||
m_ToggleButton = new OpenToggleButton( this );
|
||||
m_ToggleButton->SetBounds( 2, 2, 13, 13 );
|
||||
m_ToggleButton->onToggle.Add( this, &TreeNode::OnToggleButtonPress );
|
||||
m_ToggleButton = new OpenToggleButton(this);
|
||||
m_ToggleButton->SetBounds(2, 2, 13, 13);
|
||||
m_ToggleButton->onToggle.Add(this, &TreeNode::OnToggleButtonPress);
|
||||
|
||||
m_Title = new Button( this );
|
||||
m_Title->Dock( Pos::Top );
|
||||
m_Title->SetMargin( Margin( BranchLength, 0, 0, 0 ) );
|
||||
m_Title->SetAlignment( Pos::Left | Pos::CenterV );
|
||||
m_Title->SetShouldDrawBackground( false );
|
||||
m_Title->onDoubleClick.Add( this, &TreeNode::OnDoubleClickName );
|
||||
m_Title->onDown.Add( this, &TreeNode::OnClickName );
|
||||
m_Title->SetHeight( 16 );
|
||||
m_Title = new Button(this);
|
||||
m_Title->Dock(Pos::Top);
|
||||
m_Title->SetMargin(Margin(BranchLength, 0, 0, 0));
|
||||
m_Title->SetAlignment(Pos::Left | Pos::CenterV);
|
||||
m_Title->SetShouldDrawBackground(false);
|
||||
m_Title->onDoubleClick.Add(this, &TreeNode::OnDoubleClickName);
|
||||
m_Title->onDown.Add(this, &TreeNode::OnClickName);
|
||||
m_Title->SetHeight(16);
|
||||
|
||||
m_InnerPanel = new Base( this );
|
||||
m_InnerPanel->Dock( Pos::Top );
|
||||
m_InnerPanel->SetHeight( 100 );
|
||||
m_InnerPanel->SetMargin( Margin( TreeIndentation, 1, 0, 0 ) );
|
||||
m_InnerPanel = new Base(this);
|
||||
m_InnerPanel->Dock(Pos::Top);
|
||||
m_InnerPanel->SetHeight(100);
|
||||
m_InnerPanel->SetMargin(Margin(TreeIndentation, 1, 0, 0));
|
||||
m_InnerPanel->Hide();
|
||||
|
||||
m_bRoot = false;
|
||||
@@ -60,77 +58,75 @@ GWEN_CONTROL_CONSTRUCTOR( TreeNode )
|
||||
m_bSelectable = true;
|
||||
}
|
||||
|
||||
void TreeNode::Render( Skin::Base* skin )
|
||||
void TreeNode::Render(Skin::Base* skin)
|
||||
{
|
||||
int iBottom = 0;
|
||||
if ( m_InnerPanel->Children.size() > 0 )
|
||||
if (m_InnerPanel->Children.size() > 0)
|
||||
{
|
||||
iBottom = m_InnerPanel->Children.back()->Y() + m_InnerPanel->Y();
|
||||
}
|
||||
|
||||
skin->DrawTreeNode( this, m_InnerPanel->Visible(), IsSelected(), m_Title->Height(), m_Title->TextRight(), m_ToggleButton->Y() + m_ToggleButton->Height() * 0.5, iBottom, GetParent() == m_TreeControl );
|
||||
|
||||
skin->DrawTreeNode(this, m_InnerPanel->Visible(), IsSelected(), m_Title->Height(), m_Title->TextRight(), m_ToggleButton->Y() + m_ToggleButton->Height() * 0.5, iBottom, GetParent() == m_TreeControl);
|
||||
}
|
||||
|
||||
TreeNode* TreeNode::AddNode( const UnicodeString& strLabel )
|
||||
TreeNode* TreeNode::AddNode(const UnicodeString& strLabel)
|
||||
{
|
||||
// int sz = sizeof(TreeNode);
|
||||
TreeNode* node = new TreeNode( this );
|
||||
node->SetText( strLabel );
|
||||
node->Dock( Pos::Top );
|
||||
node->SetRoot( this->DynamicCastTreeControl() != NULL );
|
||||
node->SetTreeControl( m_TreeControl );
|
||||
// int sz = sizeof(TreeNode);
|
||||
TreeNode* node = new TreeNode(this);
|
||||
node->SetText(strLabel);
|
||||
node->Dock(Pos::Top);
|
||||
node->SetRoot(this->DynamicCastTreeControl() != NULL);
|
||||
node->SetTreeControl(m_TreeControl);
|
||||
|
||||
if ( m_TreeControl )
|
||||
if (m_TreeControl)
|
||||
{
|
||||
m_TreeControl->OnNodeAdded( node );
|
||||
m_TreeControl->OnNodeAdded(node);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
TreeNode* TreeNode::AddNode( const String& strLabel )
|
||||
TreeNode* TreeNode::AddNode(const String& strLabel)
|
||||
{
|
||||
return AddNode( Utility::StringToUnicode( strLabel ) );
|
||||
return AddNode(Utility::StringToUnicode(strLabel));
|
||||
}
|
||||
|
||||
|
||||
void TreeNode::Layout( Skin::Base* skin )
|
||||
void TreeNode::Layout(Skin::Base* skin)
|
||||
{
|
||||
if ( m_ToggleButton )
|
||||
if (m_ToggleButton)
|
||||
{
|
||||
if ( m_InnerPanel->NumChildren() == 0 )
|
||||
if (m_InnerPanel->NumChildren() == 0)
|
||||
{
|
||||
m_ToggleButton->Hide();
|
||||
m_ToggleButton->SetToggleState( false );
|
||||
m_ToggleButton->SetToggleState(false);
|
||||
m_InnerPanel->Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ToggleButton->Show();
|
||||
m_InnerPanel->SizeToChildren( false, true );
|
||||
m_InnerPanel->SizeToChildren(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
BaseClass::Layout( skin );
|
||||
BaseClass::Layout(skin);
|
||||
}
|
||||
//too many calls to PostLayout...
|
||||
//int numCalls = 0xfd;
|
||||
void TreeNode::PostLayout( Skin::Base* /*skin*/ )
|
||||
void TreeNode::PostLayout(Skin::Base* /*skin*/)
|
||||
{
|
||||
|
||||
//int bla = numCalls&0xffff;
|
||||
//if (bla==0)
|
||||
// printf("TreeNode::PostLayout numCalls = %d\n", numCalls);
|
||||
|
||||
//numCalls++;
|
||||
if ( SizeToChildren( false, true ) )
|
||||
if (SizeToChildren(false, true))
|
||||
{
|
||||
InvalidateParent();
|
||||
}
|
||||
}
|
||||
|
||||
void TreeNode::SetText( const UnicodeString& text ){ m_Title->SetText( text ); };
|
||||
void TreeNode::SetText( const String& text ){ m_Title->SetText( text ); };
|
||||
void TreeNode::SetText(const UnicodeString& text) { m_Title->SetText(text); };
|
||||
void TreeNode::SetText(const String& text) { m_Title->SetText(text); };
|
||||
|
||||
UnicodeString TreeNode::GetText() const
|
||||
{
|
||||
@@ -138,11 +134,10 @@ UnicodeString TreeNode::GetText() const
|
||||
return bla;
|
||||
}
|
||||
|
||||
|
||||
void TreeNode::Open()
|
||||
{
|
||||
m_InnerPanel->Show();
|
||||
if ( m_ToggleButton ) m_ToggleButton->SetToggleState( true );
|
||||
if (m_ToggleButton) m_ToggleButton->SetToggleState(true);
|
||||
Invalidate();
|
||||
if (m_TreeControl)
|
||||
m_TreeControl->ForceUpdateScrollBars();
|
||||
@@ -151,8 +146,8 @@ void TreeNode::Open()
|
||||
void TreeNode::Close()
|
||||
{
|
||||
m_InnerPanel->Hide();
|
||||
if ( m_ToggleButton ) m_ToggleButton->SetToggleState( false );
|
||||
|
||||
if (m_ToggleButton) m_ToggleButton->SetToggleState(false);
|
||||
|
||||
Invalidate();
|
||||
if (m_TreeControl)
|
||||
m_TreeControl->ForceUpdateScrollBars();
|
||||
@@ -163,21 +158,20 @@ void TreeNode::ExpandAll()
|
||||
Open();
|
||||
|
||||
Base::List& children = m_InnerPanel->GetChildren();
|
||||
for ( Base::List::iterator iter = children.begin(); iter != children.end(); ++iter )
|
||||
for (Base::List::iterator iter = children.begin(); iter != children.end(); ++iter)
|
||||
{
|
||||
TreeNode* pChild = (*iter)->DynamicCastTreeNode();
|
||||
if ( !pChild ) continue;
|
||||
if (!pChild) continue;
|
||||
|
||||
pChild->ExpandAll();
|
||||
}
|
||||
}
|
||||
|
||||
Button* TreeNode::GetButton(){ return m_Title; }
|
||||
Button* TreeNode::GetButton() { return m_Title; }
|
||||
|
||||
|
||||
void TreeNode::OnToggleButtonPress( Base* /*control*/ )
|
||||
void TreeNode::OnToggleButtonPress(Base* /*control*/)
|
||||
{
|
||||
if ( m_ToggleButton->GetToggleState() )
|
||||
if (m_ToggleButton->GetToggleState())
|
||||
{
|
||||
Open();
|
||||
}
|
||||
@@ -187,33 +181,33 @@ void TreeNode::OnToggleButtonPress( Base* /*control*/ )
|
||||
}
|
||||
}
|
||||
|
||||
void TreeNode::OnDoubleClickName( Base* /*control*/ )
|
||||
void TreeNode::OnDoubleClickName(Base* /*control*/)
|
||||
{
|
||||
if ( !m_ToggleButton->Visible() ) return;
|
||||
if (!m_ToggleButton->Visible()) return;
|
||||
|
||||
m_ToggleButton->Toggle();
|
||||
}
|
||||
|
||||
void TreeNode::OnClickName( Base* /*control*/ )
|
||||
void TreeNode::OnClickName(Base* /*control*/)
|
||||
{
|
||||
onNamePress.Call( this );
|
||||
onNamePress.Call(this);
|
||||
|
||||
SetSelected( !IsSelected() );
|
||||
SetSelected(!IsSelected());
|
||||
}
|
||||
|
||||
void TreeNode::SetSelected( bool b )
|
||||
{
|
||||
if ( !m_bSelectable ) return;
|
||||
if ( m_bSelected == b ) return;
|
||||
void TreeNode::SetSelected(bool b)
|
||||
{
|
||||
if (!m_bSelectable) return;
|
||||
if (m_bSelected == b) return;
|
||||
|
||||
m_bSelected = b;
|
||||
m_bSelected = b;
|
||||
|
||||
onSelectChange.Call( this );
|
||||
onSelectChange.Call(this);
|
||||
|
||||
if ( m_bSelected )
|
||||
onSelect.Call( this );
|
||||
if (m_bSelected)
|
||||
onSelect.Call(this);
|
||||
else
|
||||
onUnselect.Call( this );
|
||||
onUnselect.Call(this);
|
||||
}
|
||||
|
||||
void TreeNode::DeselectAll()
|
||||
@@ -221,33 +215,31 @@ void TreeNode::DeselectAll()
|
||||
m_bSelected = false;
|
||||
|
||||
Base::List& children = m_InnerPanel->GetChildren();
|
||||
for ( Base::List::iterator iter = children.begin(); iter != children.end(); ++iter )
|
||||
for (Base::List::iterator iter = children.begin(); iter != children.end(); ++iter)
|
||||
{
|
||||
TreeNode* pChild = (*iter)->DynamicCastTreeNode();
|
||||
if ( !pChild ) continue;
|
||||
if (!pChild) continue;
|
||||
|
||||
pChild->DeselectAll( );
|
||||
pChild->DeselectAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TreeNode::iterate(int action, int* curIndex, int* targetIndex)
|
||||
{
|
||||
|
||||
Gwen::String name = Gwen::Utility::UnicodeToString(m_Title->GetText());
|
||||
|
||||
// int actualIndex = curIndex? *curIndex : -1;
|
||||
|
||||
// int actualIndex = curIndex? *curIndex : -1;
|
||||
//printf("iterated over item %d with name = %s\n", actualIndex, name.c_str());
|
||||
|
||||
if (action==ITERATE_ACTION_SELECT)
|
||||
if (action == ITERATE_ACTION_SELECT)
|
||||
{
|
||||
if (curIndex && targetIndex)
|
||||
{
|
||||
if ((*curIndex)==(*targetIndex))
|
||||
if ((*curIndex) == (*targetIndex))
|
||||
{
|
||||
SetSelected(true);
|
||||
|
||||
*targetIndex=-1;
|
||||
|
||||
*targetIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,7 +249,7 @@ void TreeNode::iterate(int action, int* curIndex, int* targetIndex)
|
||||
//printf("current selected: name = %s\n", name.c_str());
|
||||
switch (action)
|
||||
{
|
||||
case ITERATE_ACTION_DESELECT_INDEX:
|
||||
case ITERATE_ACTION_DESELECT_INDEX:
|
||||
{
|
||||
if (targetIndex && curIndex)
|
||||
{
|
||||
@@ -266,7 +258,7 @@ void TreeNode::iterate(int action, int* curIndex, int* targetIndex)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ITERATE_ACTION_FIND_SELECTED_INDEX:
|
||||
case ITERATE_ACTION_FIND_SELECTED_INDEX:
|
||||
{
|
||||
if (targetIndex && curIndex)
|
||||
{
|
||||
@@ -274,24 +266,34 @@ void TreeNode::iterate(int action, int* curIndex, int* targetIndex)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ITERATE_ACTION_OPEN:
|
||||
case ITERATE_ACTION_OPEN:
|
||||
{
|
||||
Open();
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case ITERATE_ACTION_CLOSE:
|
||||
{
|
||||
//either close or select parent
|
||||
if (this->GetChildren().size())
|
||||
case ITERATE_ACTION_CLOSE:
|
||||
{
|
||||
if (m_ToggleButton && m_ToggleButton->GetToggleState())
|
||||
//either close or select parent
|
||||
if (this->GetChildren().size())
|
||||
{
|
||||
Close();
|
||||
} else
|
||||
if (m_ToggleButton && m_ToggleButton->GetToggleState())
|
||||
{
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
TreeNode* pChild = (GetParent())->DynamicCastTreeNode();
|
||||
TreeControl* pChild2 = (GetParent())->DynamicCastTreeControl();
|
||||
if (pChild && !pChild2)
|
||||
{
|
||||
SetSelected(false);
|
||||
pChild->SetSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
TreeNode* pChild = (GetParent())->DynamicCastTreeNode();
|
||||
TreeControl* pChild2 = (GetParent())->DynamicCastTreeControl();
|
||||
if (pChild && !pChild2)
|
||||
@@ -300,22 +302,10 @@ void TreeNode::iterate(int action, int* curIndex, int* targetIndex)
|
||||
pChild->SetSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
TreeNode* pChild = (GetParent())->DynamicCastTreeNode();
|
||||
TreeControl* pChild2 = (GetParent())->DynamicCastTreeControl();
|
||||
if (pChild && !pChild2)
|
||||
{
|
||||
SetSelected(false);
|
||||
pChild->SetSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
default:
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -326,27 +316,24 @@ void TreeNode::iterate(int action, int* curIndex, int* targetIndex)
|
||||
|
||||
bool needsRecursion = true;
|
||||
|
||||
if (action == ITERATE_ACTION_FIND_SELECTED_INDEX || action==ITERATE_ACTION_SELECT || action==ITERATE_ACTION_DESELECT_INDEX)
|
||||
if (action == ITERATE_ACTION_FIND_SELECTED_INDEX || action == ITERATE_ACTION_SELECT || action == ITERATE_ACTION_DESELECT_INDEX)
|
||||
{
|
||||
if (m_ToggleButton && !m_ToggleButton->GetToggleState())
|
||||
{
|
||||
needsRecursion=false;
|
||||
needsRecursion = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (needsRecursion)
|
||||
{
|
||||
Base::List& children = m_InnerPanel->GetChildren();
|
||||
for ( Base::List::iterator iter = children.begin(); iter != children.end(); ++iter )
|
||||
for (Base::List::iterator iter = children.begin(); iter != children.end(); ++iter)
|
||||
{
|
||||
TreeNode* pChild = (*iter)->DynamicCastTreeNode();
|
||||
if ( !pChild )
|
||||
if (!pChild)
|
||||
continue;
|
||||
|
||||
pChild->iterate(action , curIndex, targetIndex);
|
||||
pChild->iterate(action, curIndex, targetIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user