applied patch 415912 (fixing problems with wxGrid attrs)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10178 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -560,6 +560,16 @@ private:
|
|||||||
class WXDLLEXPORT wxGridCellAttr
|
class WXDLLEXPORT wxGridCellAttr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum wxAttrKind
|
||||||
|
{
|
||||||
|
Any,
|
||||||
|
Default,
|
||||||
|
Cell,
|
||||||
|
Row,
|
||||||
|
Col,
|
||||||
|
Merged
|
||||||
|
};
|
||||||
|
|
||||||
// ctors
|
// ctors
|
||||||
wxGridCellAttr()
|
wxGridCellAttr()
|
||||||
{
|
{
|
||||||
@@ -583,6 +593,7 @@ public:
|
|||||||
|
|
||||||
// creates a new copy of this object
|
// creates a new copy of this object
|
||||||
wxGridCellAttr *Clone() const;
|
wxGridCellAttr *Clone() const;
|
||||||
|
void MergeWith(wxGridCellAttr *mergefrom);
|
||||||
|
|
||||||
// this class is ref counted: it is created with ref count of 1, so
|
// this class is ref counted: it is created with ref count of 1, so
|
||||||
// calling DecRef() once will delete it. Calling IncRef() allows to lock
|
// calling DecRef() once will delete it. Calling IncRef() allows to lock
|
||||||
@@ -599,7 +610,8 @@ public:
|
|||||||
m_hAlign = hAlign;
|
m_hAlign = hAlign;
|
||||||
m_vAlign = vAlign;
|
m_vAlign = vAlign;
|
||||||
}
|
}
|
||||||
void SetReadOnly(bool isReadOnly = TRUE) { m_isReadOnly = isReadOnly; }
|
void SetReadOnly(bool isReadOnly = TRUE)
|
||||||
|
{ m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; }
|
||||||
|
|
||||||
// takes ownership of the pointer
|
// takes ownership of the pointer
|
||||||
void SetRenderer(wxGridCellRenderer *renderer)
|
void SetRenderer(wxGridCellRenderer *renderer)
|
||||||
@@ -607,6 +619,8 @@ public:
|
|||||||
void SetEditor(wxGridCellEditor* editor)
|
void SetEditor(wxGridCellEditor* editor)
|
||||||
{ wxSafeDecRef(m_editor); m_editor = editor; }
|
{ wxSafeDecRef(m_editor); m_editor = editor; }
|
||||||
|
|
||||||
|
void SetKind(wxAttrKind kind) { m_attrkind = kind; }
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
bool HasTextColour() const { return m_colText.Ok(); }
|
bool HasTextColour() const { return m_colText.Ok(); }
|
||||||
bool HasBackgroundColour() const { return m_colBack.Ok(); }
|
bool HasBackgroundColour() const { return m_colBack.Ok(); }
|
||||||
@@ -614,6 +628,7 @@ public:
|
|||||||
bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); }
|
bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); }
|
||||||
bool HasRenderer() const { return m_renderer != NULL; }
|
bool HasRenderer() const { return m_renderer != NULL; }
|
||||||
bool HasEditor() const { return m_editor != NULL; }
|
bool HasEditor() const { return m_editor != NULL; }
|
||||||
|
bool HasReadWriteMode() const { return m_isReadOnly != Unset; }
|
||||||
|
|
||||||
const wxColour& GetTextColour() const;
|
const wxColour& GetTextColour() const;
|
||||||
const wxColour& GetBackgroundColour() const;
|
const wxColour& GetBackgroundColour() const;
|
||||||
@@ -622,20 +637,31 @@ public:
|
|||||||
wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
|
wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
|
||||||
wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
|
wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
|
||||||
|
|
||||||
bool IsReadOnly() const { return m_isReadOnly; }
|
bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; }
|
||||||
|
|
||||||
|
wxAttrKind GetKind() { return m_attrkind; }
|
||||||
|
|
||||||
void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
|
void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum wxAttrReadMode
|
||||||
|
{
|
||||||
|
Unset = -1,
|
||||||
|
ReadWrite,
|
||||||
|
ReadOnly
|
||||||
|
};
|
||||||
|
|
||||||
// the common part of all ctors
|
// the common part of all ctors
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
m_nRef = 1;
|
m_nRef = 1;
|
||||||
|
|
||||||
m_isReadOnly = FALSE;
|
m_isReadOnly = Unset;
|
||||||
|
|
||||||
m_renderer = NULL;
|
m_renderer = NULL;
|
||||||
m_editor = NULL;
|
m_editor = NULL;
|
||||||
|
|
||||||
|
m_attrkind = wxGridCellAttr::Cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the dtor is private because only DecRef() can delete us
|
// the dtor is private because only DecRef() can delete us
|
||||||
@@ -658,7 +684,9 @@ private:
|
|||||||
wxGridCellEditor* m_editor;
|
wxGridCellEditor* m_editor;
|
||||||
wxGridCellAttr* m_defGridAttr;
|
wxGridCellAttr* m_defGridAttr;
|
||||||
|
|
||||||
bool m_isReadOnly;
|
wxAttrReadMode m_isReadOnly;
|
||||||
|
|
||||||
|
wxAttrKind m_attrkind;
|
||||||
|
|
||||||
// use Clone() instead
|
// use Clone() instead
|
||||||
DECLARE_NO_COPY_CLASS(wxGridCellAttr);
|
DECLARE_NO_COPY_CLASS(wxGridCellAttr);
|
||||||
@@ -687,7 +715,8 @@ public:
|
|||||||
virtual ~wxGridCellAttrProvider();
|
virtual ~wxGridCellAttrProvider();
|
||||||
|
|
||||||
// DecRef() must be called on the returned pointer
|
// DecRef() must be called on the returned pointer
|
||||||
virtual wxGridCellAttr *GetAttr(int row, int col) const;
|
virtual wxGridCellAttr *GetAttr(int row, int col,
|
||||||
|
wxGridCellAttr::wxAttrKind kind ) const;
|
||||||
|
|
||||||
// all these functions take ownership of the pointer, don't call DecRef()
|
// all these functions take ownership of the pointer, don't call DecRef()
|
||||||
// on it
|
// on it
|
||||||
@@ -778,7 +807,9 @@ public:
|
|||||||
|
|
||||||
// by default forwarded to wxGridCellAttrProvider if any. May be
|
// by default forwarded to wxGridCellAttrProvider if any. May be
|
||||||
// overridden to handle attributes directly in the table.
|
// overridden to handle attributes directly in the table.
|
||||||
virtual wxGridCellAttr *GetAttr( int row, int col );
|
virtual wxGridCellAttr *GetAttr( int row, int col,
|
||||||
|
wxGridCellAttr::wxAttrKind kind );
|
||||||
|
|
||||||
|
|
||||||
// these functions take ownership of the pointer
|
// these functions take ownership of the pointer
|
||||||
virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
|
virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
|
||||||
|
@@ -262,7 +262,7 @@ GridFrame::GridFrame()
|
|||||||
grid->SetCellAlignment(4, 4, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
grid->SetCellAlignment(4, 4, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||||
grid->SetCellRenderer(4, 4, new MyGridCellRenderer);
|
grid->SetCellRenderer(4, 4, new MyGridCellRenderer);
|
||||||
|
|
||||||
grid->SetCellValue(3, 0, "1");
|
grid->SetCellValue(3, 0, "0");
|
||||||
grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer);
|
grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer);
|
||||||
grid->SetCellEditor(3, 0, new wxGridCellBoolEditor);
|
grid->SetCellEditor(3, 0, new wxGridCellBoolEditor);
|
||||||
|
|
||||||
@@ -271,23 +271,27 @@ GridFrame::GridFrame()
|
|||||||
attr->SetTextColour(*wxBLUE);
|
attr->SetTextColour(*wxBLUE);
|
||||||
grid->SetColAttr(5, attr);
|
grid->SetColAttr(5, attr);
|
||||||
attr = new wxGridCellAttr;
|
attr = new wxGridCellAttr;
|
||||||
attr->SetBackgroundColour(*wxBLUE);
|
attr->SetBackgroundColour(*wxRED);
|
||||||
grid->SetRowAttr(5, attr);
|
grid->SetRowAttr(5, attr);
|
||||||
|
|
||||||
grid->SetCellValue(2, 4, "a wider column");
|
grid->SetCellValue(2, 4, "a wider column");
|
||||||
grid->SetColSize(4, 120);
|
grid->SetColSize(4, 120);
|
||||||
grid->SetColMinimalWidth(4, 120);
|
grid->SetColMinimalWidth(4, 120);
|
||||||
|
|
||||||
grid->SetColFormatFloat(5);
|
grid->SetCellTextColour(5, 8, *wxGREEN);
|
||||||
grid->SetCellValue(0, 5, "3.1415");
|
grid->SetCellValue(5, 8, "Bg from row attr\nText col from cell attr");
|
||||||
grid->SetCellValue(1, 5, "1415");
|
grid->SetCellValue(5, 5, "Bg from row attr\nText col from col attr");
|
||||||
grid->SetCellValue(2, 5, "12345.67890");
|
|
||||||
|
|
||||||
grid->SetColFormatFloat(6, 6, 2);
|
grid->SetColFormatFloat(6);
|
||||||
grid->SetCellValue(0, 6, "3.1415");
|
grid->SetCellValue(0, 6, "3.1415");
|
||||||
grid->SetCellValue(1, 6, "1415");
|
grid->SetCellValue(1, 6, "1415");
|
||||||
grid->SetCellValue(2, 6, "12345.67890");
|
grid->SetCellValue(2, 6, "12345.67890");
|
||||||
|
|
||||||
|
grid->SetColFormatFloat(7, 6, 2);
|
||||||
|
grid->SetCellValue(0, 7, "3.1415");
|
||||||
|
grid->SetCellValue(1, 7, "1415");
|
||||||
|
grid->SetCellValue(2, 7, "12345.67890");
|
||||||
|
|
||||||
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
||||||
topSizer->Add( grid,
|
topSizer->Add( grid,
|
||||||
1,
|
1,
|
||||||
@@ -833,6 +837,7 @@ void GridFrame::OnBugsTable(wxCommandEvent& )
|
|||||||
frame->Show(TRUE);
|
frame->Show(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GridFrame::OnVTable(wxCommandEvent& )
|
void GridFrame::OnVTable(wxCommandEvent& )
|
||||||
{
|
{
|
||||||
static long s_sizeGrid = 10000;
|
static long s_sizeGrid = 10000;
|
||||||
@@ -898,9 +903,10 @@ MyGridCellAttrProvider::~MyGridCellAttrProvider()
|
|||||||
m_attrForOddRows->DecRef();
|
m_attrForOddRows->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col) const
|
wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
|
||||||
|
wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const
|
||||||
{
|
{
|
||||||
wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col);
|
wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
|
||||||
|
|
||||||
if ( row % 2 )
|
if ( row % 2 )
|
||||||
{
|
{
|
||||||
@@ -1256,3 +1262,5 @@ BugsGridFrame::BugsGridFrame()
|
|||||||
size.y += 10;
|
size.y += 10;
|
||||||
SetClientSize(size);
|
SetClientSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -207,7 +207,8 @@ public:
|
|||||||
MyGridCellAttrProvider();
|
MyGridCellAttrProvider();
|
||||||
virtual ~MyGridCellAttrProvider();
|
virtual ~MyGridCellAttrProvider();
|
||||||
|
|
||||||
virtual wxGridCellAttr *GetAttr(int row, int col) const;
|
virtual wxGridCellAttr *GetAttr(int row, int col,
|
||||||
|
wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxGridCellAttr *m_attrForOddRows;
|
wxGridCellAttr *m_attrForOddRows;
|
||||||
@@ -247,5 +248,6 @@ public:
|
|||||||
BugsGridFrame();
|
BugsGridFrame();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // griddemo_h
|
#endif // griddemo_h
|
||||||
|
|
||||||
|
@@ -1664,8 +1664,15 @@ wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col)
|
|||||||
{
|
{
|
||||||
if ( m_width == -1 )
|
if ( m_width == -1 )
|
||||||
{
|
{
|
||||||
|
if ( m_precision == -1 )
|
||||||
|
{
|
||||||
// default width/precision
|
// default width/precision
|
||||||
m_format = _T("%f");
|
m_format = _T("%f");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_format.Printf(_T("%%.%df"), m_precision);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( m_precision == -1 )
|
else if ( m_precision == -1 )
|
||||||
{
|
{
|
||||||
@@ -1679,6 +1686,7 @@ wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col)
|
|||||||
}
|
}
|
||||||
|
|
||||||
text.Printf(m_format, val);
|
text.Printf(m_format, val);
|
||||||
|
|
||||||
}
|
}
|
||||||
//else: text already contains the string
|
//else: text already contains the string
|
||||||
|
|
||||||
@@ -1717,8 +1725,6 @@ wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid,
|
|||||||
|
|
||||||
void wxGridCellFloatRenderer::SetParameters(const wxString& params)
|
void wxGridCellFloatRenderer::SetParameters(const wxString& params)
|
||||||
{
|
{
|
||||||
bool ok = TRUE;
|
|
||||||
|
|
||||||
if ( !params )
|
if ( !params )
|
||||||
{
|
{
|
||||||
// reset to defaults
|
// reset to defaults
|
||||||
@@ -1731,37 +1737,34 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
|
|||||||
if ( !!tmp )
|
if ( !!tmp )
|
||||||
{
|
{
|
||||||
long width;
|
long width;
|
||||||
if ( !tmp.ToLong(&width) )
|
if ( tmp.ToLong(&width) )
|
||||||
{
|
{
|
||||||
ok = FALSE;
|
SetWidth((int)width);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetWidth((int)width);
|
wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
tmp = params.AfterFirst(_T(','));
|
tmp = params.AfterFirst(_T(','));
|
||||||
if ( !!tmp )
|
if ( !!tmp )
|
||||||
{
|
{
|
||||||
long precision;
|
long precision;
|
||||||
if ( !tmp.ToLong(&precision) )
|
if ( tmp.ToLong(&precision) )
|
||||||
{
|
{
|
||||||
ok = FALSE;
|
SetPrecision((int)precision);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetPrecision((int)precision);
|
wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !ok )
|
|
||||||
{
|
|
||||||
wxLogDebug(_T("Invalid wxGridCellFloatRenderer parameter string '%s ignored"), params.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGridCellBoolRenderer
|
// wxGridCellBoolRenderer
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -1888,11 +1891,47 @@ wxGridCellAttr *wxGridCellAttr::Clone() const
|
|||||||
if ( IsReadOnly() )
|
if ( IsReadOnly() )
|
||||||
attr->SetReadOnly();
|
attr->SetReadOnly();
|
||||||
|
|
||||||
|
attr->SetKind( m_attrkind );
|
||||||
|
|
||||||
attr->SetDefAttr(m_defGridAttr);
|
attr->SetDefAttr(m_defGridAttr);
|
||||||
|
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom)
|
||||||
|
{
|
||||||
|
if ( !HasTextColour() && mergefrom->HasTextColour() )
|
||||||
|
SetTextColour(mergefrom->GetTextColour());
|
||||||
|
if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() )
|
||||||
|
SetBackgroundColour(mergefrom->GetBackgroundColour());
|
||||||
|
if ( !HasFont() && mergefrom->HasFont() )
|
||||||
|
SetFont(mergefrom->GetFont());
|
||||||
|
if ( !!HasAlignment() && mergefrom->HasAlignment() ){
|
||||||
|
int hAlign, vAlign;
|
||||||
|
mergefrom->GetAlignment( &hAlign, &vAlign);
|
||||||
|
SetAlignment(hAlign, vAlign);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Directly access member functions as GetRender/Editor don't just return
|
||||||
|
// m_renderer/m_editor
|
||||||
|
//
|
||||||
|
// Maybe add support for merge of Render and Editor?
|
||||||
|
if (!HasRenderer() && mergefrom->HasRenderer() )
|
||||||
|
{
|
||||||
|
m_renderer = mergefrom->m_renderer;
|
||||||
|
m_renderer->IncRef();
|
||||||
|
}
|
||||||
|
if ( !HasEditor() && mergefrom->HasEditor() )
|
||||||
|
{
|
||||||
|
m_editor = mergefrom->m_editor;
|
||||||
|
m_editor->IncRef();
|
||||||
|
}
|
||||||
|
if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() )
|
||||||
|
SetReadOnly(mergefrom->IsReadOnly());
|
||||||
|
|
||||||
|
SetDefAttr(mergefrom->m_defGridAttr);
|
||||||
|
}
|
||||||
|
|
||||||
const wxColour& wxGridCellAttr::GetTextColour() const
|
const wxColour& wxGridCellAttr::GetTextColour() const
|
||||||
{
|
{
|
||||||
if (HasTextColour())
|
if (HasTextColour())
|
||||||
@@ -2245,28 +2284,77 @@ void wxGridCellAttrProvider::InitData()
|
|||||||
m_data = new wxGridCellAttrProviderData;
|
m_data = new wxGridCellAttrProviderData;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col) const
|
wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col,
|
||||||
|
wxGridCellAttr::wxAttrKind kind ) const
|
||||||
{
|
{
|
||||||
wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
|
wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
|
||||||
if ( m_data )
|
if ( m_data )
|
||||||
{
|
{
|
||||||
// first look for the attribute of this specific cell
|
switch(kind)
|
||||||
attr = m_data->m_cellAttrs.GetAttr(row, col);
|
|
||||||
|
|
||||||
if ( !attr )
|
|
||||||
{
|
{
|
||||||
// then look for the col attr (col attributes are more common than
|
case (wxGridCellAttr::Any):
|
||||||
// the row ones, hence they have priority)
|
//Get cached merge attributes.
|
||||||
attr = m_data->m_colAttrs.GetAttr(col);
|
// Currenlty not used as no cache implemented as not mutiable
|
||||||
}
|
// attr = m_data->m_mergeAttr.GetAttr(row, col);
|
||||||
|
if(!attr)
|
||||||
|
{
|
||||||
|
//Basicaly implement old version.
|
||||||
|
//Also check merge cache, so we don't have to re-merge every time..
|
||||||
|
wxGridCellAttr *attrcell = (wxGridCellAttr *)NULL,
|
||||||
|
*attrrow = (wxGridCellAttr *)NULL,
|
||||||
|
*attrcol = (wxGridCellAttr *)NULL;
|
||||||
|
|
||||||
|
attrcell = m_data->m_cellAttrs.GetAttr(row, col);
|
||||||
|
attrcol = m_data->m_colAttrs.GetAttr(col);
|
||||||
|
attrrow = m_data->m_rowAttrs.GetAttr(row);
|
||||||
|
|
||||||
if ( !attr )
|
if((attrcell != attrrow) && (attrrow !=attrcol) && (attrcell != attrcol)){
|
||||||
|
// Two or move are non NULL
|
||||||
|
attr = new wxGridCellAttr;
|
||||||
|
attr->SetKind(wxGridCellAttr::Merged);
|
||||||
|
|
||||||
|
//Order important..
|
||||||
|
if(attrcell){
|
||||||
|
attr->MergeWith(attrcell);
|
||||||
|
attrcell->DecRef();
|
||||||
|
}
|
||||||
|
if(attrcol){
|
||||||
|
attr->MergeWith(attrcol);
|
||||||
|
attrcol->DecRef();
|
||||||
|
}
|
||||||
|
if(attrrow){
|
||||||
|
attr->MergeWith(attrrow);
|
||||||
|
attrrow->DecRef();
|
||||||
|
}
|
||||||
|
//store merge attr if cache implemented
|
||||||
|
//attr->IncRef();
|
||||||
|
//m_data->m_mergeAttr.SetAttr(attr, row, col);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// finally try the row attributes
|
// one or none is non null return it or null.
|
||||||
|
if(attrrow) attr = attrrow;
|
||||||
|
if(attrcol) attr = attrcol;
|
||||||
|
if(attrcell) attr = attrcell;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case (wxGridCellAttr::Cell):
|
||||||
|
attr = m_data->m_cellAttrs.GetAttr(row, col);
|
||||||
|
break;
|
||||||
|
case (wxGridCellAttr::Col):
|
||||||
|
attr = m_data->m_colAttrs.GetAttr(col);
|
||||||
|
break;
|
||||||
|
case (wxGridCellAttr::Row):
|
||||||
attr = m_data->m_rowAttrs.GetAttr(row);
|
attr = m_data->m_rowAttrs.GetAttr(row);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// unused as yet...
|
||||||
|
// (wxGridCellAttr::Default):
|
||||||
|
// (wxGridCellAttr::Merged):
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2498,10 +2586,10 @@ bool wxGridTableBase::CanHaveAttributes()
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col)
|
wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind)
|
||||||
{
|
{
|
||||||
if ( m_attrProvider )
|
if ( m_attrProvider )
|
||||||
return m_attrProvider->GetAttr(row, col);
|
return m_attrProvider->GetAttr(row, col, kind);
|
||||||
else
|
else
|
||||||
return (wxGridCellAttr *)NULL;
|
return (wxGridCellAttr *)NULL;
|
||||||
}
|
}
|
||||||
@@ -2510,6 +2598,7 @@ void wxGridTableBase::SetAttr(wxGridCellAttr* attr, int row, int col)
|
|||||||
{
|
{
|
||||||
if ( m_attrProvider )
|
if ( m_attrProvider )
|
||||||
{
|
{
|
||||||
|
attr->SetKind(wxGridCellAttr::Cell);
|
||||||
m_attrProvider->SetAttr(attr, row, col);
|
m_attrProvider->SetAttr(attr, row, col);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2524,6 +2613,7 @@ void wxGridTableBase::SetRowAttr(wxGridCellAttr *attr, int row)
|
|||||||
{
|
{
|
||||||
if ( m_attrProvider )
|
if ( m_attrProvider )
|
||||||
{
|
{
|
||||||
|
attr->SetKind(wxGridCellAttr::Row);
|
||||||
m_attrProvider->SetRowAttr(attr, row);
|
m_attrProvider->SetRowAttr(attr, row);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2538,6 +2628,7 @@ void wxGridTableBase::SetColAttr(wxGridCellAttr *attr, int col)
|
|||||||
{
|
{
|
||||||
if ( m_attrProvider )
|
if ( m_attrProvider )
|
||||||
{
|
{
|
||||||
|
attr->SetKind(wxGridCellAttr::Col);
|
||||||
m_attrProvider->SetColAttr(attr, col);
|
m_attrProvider->SetColAttr(attr, col);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -3447,6 +3538,7 @@ void wxGrid::Create()
|
|||||||
m_defaultCellAttr->SetDefAttr(m_defaultCellAttr);
|
m_defaultCellAttr->SetDefAttr(m_defaultCellAttr);
|
||||||
|
|
||||||
// Set default cell attributes
|
// Set default cell attributes
|
||||||
|
m_defaultCellAttr->SetKind(wxGridCellAttr::Default);
|
||||||
m_defaultCellAttr->SetFont(GetFont());
|
m_defaultCellAttr->SetFont(GetFont());
|
||||||
m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP);
|
m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP);
|
||||||
m_defaultCellAttr->SetTextColour(
|
m_defaultCellAttr->SetTextColour(
|
||||||
@@ -7801,6 +7893,7 @@ void wxGrid::ClearAttrCache()
|
|||||||
if ( m_attrCache.row != -1 )
|
if ( m_attrCache.row != -1 )
|
||||||
{
|
{
|
||||||
wxSafeDecRef(m_attrCache.attr);
|
wxSafeDecRef(m_attrCache.attr);
|
||||||
|
m_attrCache.attr = NULL;
|
||||||
m_attrCache.row = -1;
|
m_attrCache.row = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7843,7 +7936,7 @@ wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const
|
|||||||
wxGridCellAttr *attr;
|
wxGridCellAttr *attr;
|
||||||
if ( !LookupAttr(row, col, &attr) )
|
if ( !LookupAttr(row, col, &attr) )
|
||||||
{
|
{
|
||||||
attr = m_table ? m_table->GetAttr(row, col) : (wxGridCellAttr *)NULL;
|
attr = m_table ? m_table->GetAttr(row, col , wxGridCellAttr::Any) : (wxGridCellAttr *)NULL;
|
||||||
CacheAttr(row, col, attr);
|
CacheAttr(row, col, attr);
|
||||||
}
|
}
|
||||||
if (attr)
|
if (attr)
|
||||||
@@ -7861,25 +7954,19 @@ wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const
|
|||||||
|
|
||||||
wxGridCellAttr *wxGrid::GetOrCreateCellAttr(int row, int col) const
|
wxGridCellAttr *wxGrid::GetOrCreateCellAttr(int row, int col) const
|
||||||
{
|
{
|
||||||
wxGridCellAttr *attr;
|
wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
|
||||||
if ( !LookupAttr(row, col, &attr) || !attr )
|
|
||||||
{
|
|
||||||
wxASSERT_MSG( m_table,
|
wxASSERT_MSG( m_table,
|
||||||
_T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") );
|
_T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") );
|
||||||
|
|
||||||
attr = m_table->GetAttr(row, col);
|
attr = m_table->GetAttr(row, col, wxGridCellAttr::Cell );
|
||||||
if ( !attr )
|
if ( !attr )
|
||||||
{
|
{
|
||||||
attr = new wxGridCellAttr;
|
attr = new wxGridCellAttr;
|
||||||
|
|
||||||
// artificially inc the ref count to match DecRef() in caller
|
// artificially inc the ref count to match DecRef() in caller
|
||||||
attr->IncRef();
|
attr->IncRef();
|
||||||
|
|
||||||
m_table->SetAttr(attr, row, col);
|
m_table->SetAttr(attr, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheAttr(row, col, attr);
|
|
||||||
}
|
|
||||||
attr->SetDefAttr(m_defaultCellAttr);
|
attr->SetDefAttr(m_defaultCellAttr);
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
@@ -7911,11 +7998,16 @@ void wxGrid::SetColFormatFloat(int col, int width, int precision)
|
|||||||
|
|
||||||
void wxGrid::SetColFormatCustom(int col, const wxString& typeName)
|
void wxGrid::SetColFormatCustom(int col, const wxString& typeName)
|
||||||
{
|
{
|
||||||
wxGridCellAttr *attr = new wxGridCellAttr;
|
wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
|
||||||
|
|
||||||
|
attr = m_table->GetAttr(-1, col, wxGridCellAttr::Col );
|
||||||
|
if(!attr)
|
||||||
|
attr = new wxGridCellAttr;
|
||||||
wxGridCellRenderer *renderer = GetDefaultRendererForType(typeName);
|
wxGridCellRenderer *renderer = GetDefaultRendererForType(typeName);
|
||||||
attr->SetRenderer(renderer);
|
attr->SetRenderer(renderer);
|
||||||
|
|
||||||
SetColAttr(col, attr);
|
SetColAttr(col, attr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -7927,6 +8019,7 @@ void wxGrid::SetRowAttr(int row, wxGridCellAttr *attr)
|
|||||||
if ( CanHaveAttributes() )
|
if ( CanHaveAttributes() )
|
||||||
{
|
{
|
||||||
m_table->SetRowAttr(attr, row);
|
m_table->SetRowAttr(attr, row);
|
||||||
|
ClearAttrCache();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -7939,6 +8032,7 @@ void wxGrid::SetColAttr(int col, wxGridCellAttr *attr)
|
|||||||
if ( CanHaveAttributes() )
|
if ( CanHaveAttributes() )
|
||||||
{
|
{
|
||||||
m_table->SetColAttr(attr, col);
|
m_table->SetColAttr(attr, col);
|
||||||
|
ClearAttrCache();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user