Page 1 of 1

Render item in wxDataViewCtrl

Posted: Tue Jul 28, 2009 11:24 am
by van_user
Are exist any method to know for what item render has called?
Or I should modify my wxDataViewModel::GetValue to return struct with pointer to the item ( is it possible with wxVariant?).
Sorry for my English.

Posted: Thu Aug 06, 2009 8:01 am
by van_user
For now I use such method ( save pointer to( on) the item in Model :: GetValue as it is called before Render :: SetValue that is called before Render :: Render):
Model

Code: Select all

void Content_View_Model_Class :: GetValue( wxVariant& variant_e,
		const wxDataViewItem& item_e, unsigned int col_e)	const
{
	Node_Class* node = Get_node_from_item( item_e);
	if( node == NULL)
	{
		wxLogError( wxT( "Content_View_Model_Class :: GetValue: can`t identify node"));
		return;
	}
	variant_e. ClearList( );
	switch( col_e)
	{
		case 0:
			variant_e. Append( node -> Get_name( ));
			break;
		case 1:
			variant_e. Append( node -> Get_location( ));
			break;
		case 2:
			const Node_Class* node_by_alias( node -> Get_node_specified_by_alias( ));
			if( node_by_alias != NULL)
				variant_e. Append( node_by_alias -> Get_location( ));
			else
				variant_e. Append( wxEmptyString);
			break;
		default:
			wxLogError( wxT( "Content_View_Model_Class :: GetValue: wrong column %d"), col_e);
	};
	variant_e. Append( node);
	return;
}
Render:

Code: Select all

bool Content_View_Render_Class :: SetValue( const wxVariant& value_e)
{
	int input_paraments_quantity( value_e. GetCount( ));
	if( input_paraments_quantity != 2)
	{
		wxLogError( wxT( "Content_View_Render_Class :: SetValue."));
		wxLogError( wxT( "Wrong structure of input parameter. Current quantity is %l"),
				input_paraments_quantity);
		return false;
	}
	Item_Colours_Class correct_colours;
	if( !Styled_output)
		correct_colours = Preset_colours -> Default;
	else
	{
		Node_Class* node( reinterpret_cast< Node_Class*>( value_e[ 1]. GetVoidPtr( )));
		if( node == NULL)
		{
			wxLogError( wxT( "Content_View_Render_Class :: SetValue. Node in NULL!"));
			return false;
		}
		int node_exist_state;
//		node_exist_state = Data_container -> Eval_node_exist_state( node);
		node_exist_state = dynamic_cast< Content_View_Model_Class*>( GetOwner( ) -> GetOwner( ) -> GetModel( )) -> Get_data( ) -> Eval_node_exist_state( node);
		switch( node_exist_state)
		{
			case 0:
				if( node -> Is_directory( ))
					correct_colours = Preset_colours -> Directory_s_content_not_exist;
				else
					correct_colours = Preset_colours -> Element_not_exist;
				break;
			case 1:
				if( node -> Is_directory( ))
					correct_colours = Preset_colours -> Directory_s_content_exist;
				else
					correct_colours = Preset_colours -> Element_exist;
				break;
			case 3:
				correct_colours = Preset_colours -> Directory_s_content_exist_partly;
				break;
			default:
			{
				wxLogError( wxT( "Content_View_Render_Class :: SetValue. Unknown state of node existance."));
				wxLogError( wxT( "Location is %s. State is %d"), node -> Get_location( ), node_exist_state);
				return false;
			}
		}
		Current_pen = correct_colours. Pen;
		Current_brush = correct_colours. Brush;
		Font_colour = correct_colours. Font_colour;
		Background_colour = correct_colours. Background_colour;
	}
	Cell_value = value_e[ 0];
	return true;
}