wxGrid changing label rendering Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Simon
Earned a small fee
Earned a small fee
Posts: 23
Joined: Thu Jan 18, 2007 3:49 am
Location: Argentina, Cordoba

wxGrid changing label rendering

Post by Simon »

Hi everyone, I want to do what is in the example picture.
Is just to add a triangle inside the cell of a column label in wxGrid.
I already know how to do it on a particular cell, but not in the column label.

THANKS
Attachments
this is the triangle example
this is the triangle example
triangle.PNG (3.95 KiB) Viewed 1673 times
Simon
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester »

My class:

Code: Select all

/**********************************************************************************************/		
/* vsBaseGrid.h																		      */
/*																							  */
/* All Rights Reserved.																	  	  */
/**********************************************************************************************/

#ifndef __vsBaseGrid_H__
#define __vsBaseGrid_H__

// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include <wx/grid.h>

/**********************************************************************************************/
class vsBaseGrid: public wxGrid
{
public://///////////////////////////////////////////////////////////////////////////////////

	vsBaseGrid( wxWindow *parent, wxWindowID id,
		const wxPoint& pos = wxDefaultPosition,
		const wxSize& size = wxDefaultSize,
		long style = wxWANTS_CHARS );

	~vsBaseGrid();

	virtual wxGrid*				Clone(wxWindowID id = wxID_ANY);

	virtual int					GetColLeft( int col ) { return wxGrid::GetColLeft( col ); }
	virtual int					GetRowBottom( int row ) { return wxGrid::GetRowBottom( row ); }
	virtual int					GetRowTop( int row ) { return wxGrid::GetRowTop( row ); }

private:////////////////////////////////////////////////////////////////////////////////////

	virtual void				DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
	virtual void				DrawRowLabel( wxDC& dc, int row );
	virtual void				DrawColLabel( wxDC& dc, int row );

	DECLARE_EVENT_TABLE()
};

/**********************************************************************************************/
#endif // __vsBaseGrid_H__










/**********************************************************************************************/		
/* vsBaseGrid.cpp																		      */
/*																							  */
/* All Rights Reserved.																	  	  */
/**********************************************************************************************/

// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include "vsBaseGrid.h"

BEGIN_EVENT_TABLE(vsBaseGrid, wxGrid)
ND_EVENT_TABLE()

/**********************************************************************************************/
vsBaseGrid::vsBaseGrid( wxWindow *parent, wxWindowID id, const wxPoint& pos,
						 const wxSize& size, long style )
: wxGrid( parent, id, pos, size, style )
{
	EnableDragRowSize( false );
}

/**********************************************************************************************/
vsBaseGrid::~vsBaseGrid()
{
}

/**********************************************************************************************/
wxGrid* vsBaseGrid::Clone( wxWindowID id )
{ 
	vsBaseGrid	*t_pGrid;

	t_pGrid = new vsBaseGrid(GetParent(), id);

	//TODO

	return t_pGrid;
}

/**********************************************************************************************/
// Hide wxGrid cursor
void vsBaseGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr )
{
	//rewrite parent method for hide cursor
	return;
}

/**********************************************************************************************/
// Drawing labels for each row
void vsBaseGrid::DrawRowLabel( wxDC& dc, int row )
{
	wxGrid::DrawRowLabel( dc, row );
}

/**********************************************************************************************/
// Drawing labels for each row
void vsBaseGrid::DrawColLabel( wxDC& dc, int col )
{
	int colLeft = GetColLeft(col);
	int colCur = GetGridCursorCol();

	wxColour cl1;
	wxRect tRect( colLeft, 0, GetColWidth(col),  m_colLabelHeight );

#ifdef __WXMSW__
	cl1 = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
#else
	cl1 = *wxWHITE;
#endif

	wxColour cl2 = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
	dc.GradientFillLinear( tRect, cl1/*wxColour( 250, 249, 245 )*/, cl2/*wxColour( 192, 192, 168 )*/, wxSOUTH );
	
	
#ifdef __WXMSW__
	wxFont tFont = *wxNORMAL_FONT;
#else
	wxFont tFont = *wxSMALL_FONT;
#endif

	dc.SetFont( tFont );
	dc.DrawLabel( GetColLabelValue( col ), tRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL );

	tRect.Offset( -1, 0 );
	tRect.SetWidth( tRect.GetWidth() + 1 );
	wxColour cl3 = GetGridLineColour();
	dc.SetPen( cl3 );
	dc.SetBrush( *wxTRANSPARENT_BRUSH );
	dc.DrawRectangle( tRect );
}
Simon
Earned a small fee
Earned a small fee
Posts: 23
Joined: Thu Jan 18, 2007 3:49 am
Location: Argentina, Cordoba

Post by Simon »

THANKS A LOT. I was reading an old class reference. Where is the most up-to -date ???
Simon
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Simon wrote:THANKS A LOT. I was reading an old class reference. Where is the most up-to -date ???
http://www.wxwidgets.org/ --> at the right of the screen --> latest docs ;)
Simon
Earned a small fee
Earned a small fee
Posts: 23
Joined: Thu Jan 18, 2007 3:49 am
Location: Argentina, Cordoba

Post by Simon »

google coudn
Simon
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester »

wxWidgets/include
wxWidgets/src

:)
Post Reply