Added wxDataViewCustomRenderer::RenderText() for renderer simple text in platform dependent way, added wxDataViewSpinRenderer

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49272 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2007-10-20 20:09:10 +00:00
parent 59a722ea3a
commit 52e750fc75
9 changed files with 173 additions and 35 deletions

View File

@ -12,6 +12,7 @@ a number of ready-to-use renderers provided:
\helpref{wxDataViewProgressRenderer}{wxdataviewprogressrenderer},
\helpref{wxDataViewBitmapRenderer}{wxdataviewbitmaprenderer},
\helpref{wxDataViewDateRenderer}{wxdataviewdaterenderer}.
\helpref{wxDataViewSpinRenderer}{wxdataviewspinrenderer}.
Additionally, the user can write own renderers by deriving from
\helpref{wxDataViewCustomRenderer}{wxdataviewcustomrenderer}.
@ -467,6 +468,15 @@ Override this to render the cell. Before this is called,
\helpref{SetValue}{wxdataviewrenderersetvalue} was called
so that this instance knows what to render.
\membersection{wxDataViewCustomRenderer::RenderText}\label{wxdataviewcustomrendererrender}
\func{bool}{RenderText}{\param{const wxString\& }{text}, \param{int }{xoffset}, \param{wxRect }{cell}, \param{wxDC* }{dc}, \param{int }{state}}
This method should be called from within \helpref{Render}{wxdataviewcustomrendererrender}
whenever you need to render simple text. This will ensure that the
correct colour, font and vertical alignment will be chosen so the
text will look the same as text drawn by native renderers.
\membersection{wxDataViewCustomRenderer::RightClick}\label{wxdataviewcustomrendererrightclick}
\func{virtual bool}{RightClick}{\param{wxPoint }{cursor}, \param{wxRect }{cell}, \param{wxDataViewModel* }{model}, \param{unsigned int }{col}, \param{unsigned int }{row}}
@ -480,4 +490,29 @@ Overrride this to react to a right click.
Overrride this to start a drag operation.
\section{\class{wxDataViewSpinRenderer}}\label{wxdataviewspinrenderer}
This is a specialized renderer for rendering integer values. It
supports modifying the values in-place by using a wxSpinCtrl.
The renderer only support variants of type {\it long}.
\wxheading{Derived from}
\helpref{wxDataViewCustomRenderer}{wxdataviewcustomrenderer}
\wxheading{Include files}
<dataview.h>
\wxheading{Data structures}
\latexignore{\rtfignore{\wxheading{Members}}}
\membersection{wxDataViewSpinRenderer::wxDataViewSpinRenderer}\label{wxdataviewspinrendererwxdataviewspinrenderer}
\func{}{wxDataViewSpinRenderer}{\param{int }{min}, \param{int }{max}, \param{wxDataViewCellMode }{mode = wxDATAVIEW\_CELL\_EDITABLE}, \param{int }{alignment = wxDVR\_DEFAULT\_ALIGNMENT}}
Constructor. {\it min} and {\it max} indicate the minimum und
maximum values of for the wxSpinCtrl.

View File

@ -713,6 +713,29 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
#include "wx/generic/dataview.h"
#endif
// -------------------------------------
// wxDataViewSpinRenderer
// -------------------------------------
class wxDataViewSpinRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewSpinRenderer( int min, int max,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual bool HasEditorCtrl() { return true; }
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
virtual bool Render( wxRect rect, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool SetValue( const wxVariant &value );
virtual bool GetValue( wxVariant &value ) const;
private:
long m_data;
long m_min,m_max;
};
//-----------------------------------------------------------------------------
// wxDataViewTreeStore
//-----------------------------------------------------------------------------

View File

@ -99,6 +99,8 @@ public:
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
};

View File

@ -122,6 +122,9 @@ public:
virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const = 0;
virtual bool Activate( wxRect cell,

View File

@ -118,6 +118,8 @@ public:
virtual ~wxDataViewCustomRenderer(void);
void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
//
// methods handling render space
//

View File

@ -19,6 +19,10 @@
#include "wx/dataview.h"
#include "wx/spinctrl.h"
#include "wx/dc.h"
#include "wx/settings.h"
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/icon.h"
@ -971,6 +975,58 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED)
// -------------------------------------
// wxDataViewSpinRenderer
// -------------------------------------
wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) :
wxDataViewCustomRenderer( "long", mode, alignment )
{
m_min = min;
m_max = max;
}
wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
{
long l = value;
return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString,
labelRect.GetTopLeft(), labelRect.GetSize(), wxSP_ARROW_KEYS, m_min, m_max, l );
}
bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
{
wxSpinCtrl *sc = (wxSpinCtrl*) editor;
long l = sc->GetValue();
value = l;
return true;
}
bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
{
wxString str;
str.Printf( "%d", (int) m_data );
RenderText( str, 0, rect, dc, state );
return true;
}
wxSize wxDataViewSpinRenderer::GetSize() const
{
return wxSize(80,16);
}
bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
{
m_data = value.GetLong();
return true;
}
bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
{
value = m_data;
return true;
}
//-----------------------------------------------------------------------------
// wxDataViewTreeStore
//-----------------------------------------------------------------------------

View File

@ -635,6 +635,16 @@ wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
{
}
void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
{
wxDataViewCtrl *view = GetOwner()->GetOwner();
wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
view->GetForegroundColour();
dc->SetTextForeground(col);
dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
}
// ---------------------------------------------------------
// wxDataViewTextRenderer
// ---------------------------------------------------------
@ -681,15 +691,7 @@ bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVarian
bool wxDataViewTextRenderer::Render( wxRect cell, wxDC *dc, int state )
{
wxDataViewCtrl *view = GetOwner()->GetOwner();
wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
view->GetForegroundColour();
dc->SetTextForeground(col);
dc->DrawText( m_text, cell.x, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
// dc->DrawText( m_text, cell.x, cell.y );
RenderText( m_text, 0, cell, dc, state );
return true;
}
@ -950,12 +952,10 @@ bool wxDataViewDateRenderer::GetValue( wxVariant &value ) const
return true;
}
bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state )
{
dc->SetFont( GetOwner()->GetOwner()->GetFont() );
wxString tmp = m_date.FormatDate();
dc->DrawText( tmp, cell.x, cell.y );
RenderText( tmp, 0, cell, dc, state );
return true;
}
@ -1019,24 +1019,15 @@ bool wxDataViewIconTextRenderer::GetValue( wxVariant &value ) const
bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state )
{
wxDataViewCtrl *view = GetOwner()->GetOwner();
dc->SetFont( view->GetFont() );
wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
view->GetForegroundColour();
dc->SetTextForeground(col);
int xoffset = 0;
const wxIcon &icon = m_value.GetIcon();
if (icon.IsOk())
{
dc->DrawIcon( icon, cell.x, cell.y + ((cell.height - icon.GetHeight()) / 2));
cell.x += icon.GetWidth()+4;
xoffset = icon.GetWidth()+4;
}
dc->DrawText( m_value.GetText(), cell.x, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
RenderText( m_value.GetText(), xoffset, cell, dc, state );
return true;
}

View File

@ -28,7 +28,7 @@
#include "wx/icon.h"
#include "wx/list.h"
#include "wx/listimpl.cpp"
#include "wx/settings.h"
#include "wx/gtk/private.h"
#include "wx/gtk/win_gtk.h"
@ -1673,6 +1673,16 @@ wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
Init(mode, align);
}
void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
{
wxDataViewCtrl *view = GetOwner()->GetOwner();
wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
view->GetForegroundColour();
dc->SetTextForeground(col);
dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
}
bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align)
{
GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new();
@ -1874,8 +1884,7 @@ bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state )
{
dc->SetFont( GetOwner()->GetOwner()->GetFont() );
wxString tmp = m_date.FormatDate();
dc->DrawText( tmp, cell.x, cell.y );
RenderText( tmp, 0, cell, dc, state );
return true;
}
@ -1936,23 +1945,30 @@ bool wxDataViewIconTextRenderer::GetValue( wxVariant &value ) const
bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state )
{
dc->SetFont( GetOwner()->GetOwner()->GetFont() );
const wxIcon &icon = m_value.GetIcon();
int offset = 0;
if (icon.IsOk())
{
dc->DrawIcon( icon, cell.x, cell.y ); // TODO centre
cell.x += icon.GetWidth()+4;
int yoffset = wxMax( 0, (cell.height - icon.GetHeight()) / 2 );
dc->DrawIcon( icon, cell.x, cell.y + yoffset );
offset = icon.GetWidth() + 4;
}
dc->DrawText( m_value.GetText(), cell.x, cell.y );
RenderText( m_value.GetText(), offset, cell, dc, state );
return true;
}
wxSize wxDataViewIconTextRenderer::GetSize() const
{
return wxSize(80,16); // TODO
wxSize size;
if (m_value.GetIcon().IsOk())
size.x = 4 + m_value.GetIcon().GetWidth();
wxCoord x,y,d;
GetView()->GetTextExtent( m_value.GetText(), &x, &y, &d );
size.x += x;
size.y = y+d;
return size;
}
wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )

View File

@ -379,6 +379,16 @@ wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
delete this->m_DCPtr;
} /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
{
wxDataViewCtrl *view = GetOwner()->GetOwner();
wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
view->GetForegroundColour();
dc->SetTextForeground(col);
dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
}
wxDC* wxDataViewCustomRenderer::GetDC(void)
{
if (this->m_DCPtr == NULL)