bool Cleared();
void Resort()
{
- SortPrepare();
- m_root->Resort();
+ if (m_root)
+ {
+ SortPrepare();
+ m_root->Resort();
+ }
UpdateDisplay();
}
m_dc = NULL;
m_align = align;
m_mode = mode;
+ m_wantsAttr = false;
+ m_hasAttr = false;
}
wxDataViewRenderer::~wxDataViewRenderer()
return wxSize(80,20);
}
+// ---------------------------------------------------------
+// wxDataViewTextRendererAttr
+// ---------------------------------------------------------
+
+IMPLEMENT_CLASS(wxDataViewTextRendererAttr, wxDataViewTextRenderer)
+
+wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString &varianttype,
+ wxDataViewCellMode mode, int align ) :
+ wxDataViewTextRenderer( varianttype, mode, align )
+{
+ m_wantsAttr = true;
+}
+
+bool wxDataViewTextRendererAttr::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
+{
+ wxFont font;
+ wxColour colour;
+
+ if (m_hasAttr)
+ {
+ if (m_attr.HasColour())
+ {
+ colour = dc->GetTextForeground();
+ dc->SetTextForeground( m_attr.GetColour() );
+ }
+
+ if (m_attr.GetBold() || m_attr.GetItalic())
+ {
+ font = dc->GetFont();
+ wxFont myfont = font;
+ if (m_attr.GetBold())
+ myfont.SetWeight( wxFONTWEIGHT_BOLD );
+ if (m_attr.GetItalic())
+ myfont.SetStyle( wxFONTSTYLE_ITALIC );
+ dc->SetFont( myfont );
+ }
+ }
+
+ dc->DrawText( m_text, cell.x, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
+
+ // restore dc
+ if (m_hasAttr)
+ {
+ if (m_attr.HasColour())
+ dc->SetTextForeground( colour );
+
+ if (m_attr.GetBold() || m_attr.GetItalic())
+ dc->SetFont( font );
+ }
+
+ return true;
+}
+
+
// ---------------------------------------------------------
// wxDataViewBitmapRenderer
// ---------------------------------------------------------
#if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW
+#ifndef HDS_DRAGDROP
+ #define HDS_DRAGDROP 0x0040
+#endif
+#ifndef HDS_FULLDRAG
+ #define HDS_FULLDRAG 0x0080
+#endif
+
// implemented in msw/listctrl.cpp:
int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick);
m_owner = parent;
m_scrollOffsetX = 0;
- m_buttonHeight = wxRendererNative::Get().GetHeaderButtonHeight( this );
+ m_buttonHeight = wxRendererNative::Get().GetHeaderButtonHeight( this ) + 10;
int x = pos.x == wxDefaultCoord ? 0 : pos.x,
y = pos.y == wxDefaultCoord ? 0 : pos.y,
// create the native WC_HEADER window:
WXHWND hwndParent = (HWND)parent->GetHandle();
- WXDWORD msStyle = WS_CHILD | HDS_BUTTONS | HDS_HORZ | HDS_HOTTRACK | HDS_FULLDRAG;
+ WXDWORD msStyle = WS_CHILD | HDS_DRAGDROP | HDS_BUTTONS | HDS_HORZ | HDS_HOTTRACK | HDS_FULLDRAG;
if ( m_isShown )
msStyle |= WS_VISIBLE;
return wxSize(80, m_buttonHeight );
}
-#ifndef HDF_SORTUP
-#define HDF_SORTUP 0x0400
-#endif
-#ifndef HDF_SORTDOWN
-#define HDF_SORTDOWN 0x0200
-#endif
-
void wxDataViewHeaderWindowMSW::UpdateDisplay()
{
// remove old columns
default:
// such alignment is not allowed for the column header!
- wxFAIL;
+ break; // wxFAIL;
}
SendMessage((HWND)m_hWnd, HDM_INSERTITEM,
int f)
{
// TODO: why is there a border + 2px around it?
- wxControl::DoSetSize( x+m_scrollOffsetX-2, y-2, w-m_scrollOffsetX+4, h+4, f );
+ wxControl::DoSetSize( x+m_scrollOffsetX+1, y+1, w-m_scrollOffsetX-2, h-2, f );
}
#else // !defined(__WXMSW__)
unsigned int item_start = wxMax( 0, (update.y / m_lineHeight) );
unsigned int item_count =
wxMin( (int)(((update.y + update.height) / m_lineHeight) - item_start + 1),
- (int)(GetRowCount( )- item_start) );
+ (int)(GetRowCount( ) - item_start));
unsigned int item_last = item_start + item_count;
// compute which columns needs to be redrawn
{
// get the cell value and set it into the renderer
wxVariant value;
- wxDataViewTreeNode * node = GetTreeNodeByRow(item);
- if( node == NULL )
- continue;
+ wxDataViewTreeNode *node = NULL;
+ wxDataViewItem dataitem;
+
+ if (m_root)
+ {
+ node = GetTreeNodeByRow(item);
+ if( node == NULL )
+ continue;
- wxDataViewItem dataitem = node->GetItem();
+ dataitem = node->GetItem();
- if ((i > 0) && model->IsContainer(dataitem) && !model->HasContainerColumns(dataitem))
- continue;
+ if ((i > 0) && model->IsContainer(dataitem) && !model->HasContainerColumns(dataitem))
+ continue;
+ }
+ else
+ {
+ dataitem = wxDataViewItem( (void*) item );
+ }
model->GetValue( value, dataitem, col->GetModelColumn());
cell->SetValue( value );
+
+ if (cell->GetWantsAttr())
+ {
+ wxDataViewItemAttr attr;
+ bool ret = model->GetAttr( dataitem, col->GetModelColumn(), attr );
+ if (ret)
+ cell->SetAttr( attr );
+ cell->SetHasAttr( ret );
+ }
// update the y offset
cell_rect.y = item * m_lineHeight;
//Draw the expander here.
- int indent = node->GetIndentLevel();
- if( col == expander )
+ int indent = 0;
+ if ((m_root) && (col == expander))
{
+ indent = node->GetIndentLevel();
+
//Calculate the indent first
indent = cell_rect.x + GetOwner()->GetIndent() * indent;
}
else
{
- // I am wandering whether we should draw dot lines between tree nodes
- delete node;
- //Yes, if the node does not have any child, it must be a leaf which mean that it is a temporarily created by GetTreeNodeByRow
+ // I am wondering whether we should draw dot lines between tree nodes
+ if (node)
+ delete node;
+ // Yes, if the node does not have any child, it must be a leaf which
+ // mean that it is a temporarily created by GetTreeNodeByRow
}
//force the expander column to left-center align
wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const
{
- RowToItemJob job( row, -2 );
- Walker( m_root , job );
- return job.GetResult();
+ if (!m_root)
+ {
+ return wxDataViewItem( (void*) row );
+ }
+ else
+ {
+ RowToItemJob job( row, -2 );
+ Walker( m_root , job );
+ return job.GetResult();
+ }
}
class RowToTreeNodeJob: public DoJob
wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row)
{
- RowToTreeNodeJob job( row , -2, m_root );
- Walker( m_root , job );
- return job.GetResult();
+ if (!m_root)
+ {
+ return NULL;
+ }
+ else
+ {
+ RowToTreeNodeJob job( row , -2, m_root );
+ Walker( m_root , job );
+ return job.GetResult();
+ }
}
wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, const wxDataViewItem & item )
int wxDataViewMainWindow::RecalculateCount()
{
- return m_root->GetSubTreeCount();
+ if (!m_root)
+ {
+ wxDataViewIndexListModel *list_model = (wxDataViewIndexListModel*) GetOwner()->GetModel();
+#ifndef __WXMAC__
+ return list_model->GetLastIndex() + 1;
+#else
+ return list_model->GetLastIndex() - 1;
+#endif
+ }
+ else
+ {
+ return m_root->GetSubTreeCount();
+ }
}
class ItemToRowJob : public DoJob
if( model == NULL )
return -1;
- if( !item.IsOk() )
- return -1;
-
- //Compose the a parent-chain of the finding item
- ItemList list;
- wxDataViewItem * pItem = NULL;
- list.DeleteContents( true );
- wxDataViewItem it( item );
- while( it.IsOk() )
+ if (!m_root)
{
- pItem = new wxDataViewItem( it );
- list.Insert( pItem );
- it = model->GetParent( it );
+ return wxPtrToUInt( item.GetID() );
}
- pItem = new wxDataViewItem( );
- list.Insert( pItem );
+ else
+ {
+ if( !item.IsOk() )
+ return -1;
+
+ //Compose the a parent-chain of the finding item
+ ItemList list;
+ wxDataViewItem * pItem = NULL;
+ list.DeleteContents( true );
+ wxDataViewItem it( item );
+ while( it.IsOk() )
+ {
+ pItem = new wxDataViewItem( it );
+ list.Insert( pItem );
+ it = model->GetParent( it );
+ }
+ pItem = new wxDataViewItem( );
+ list.Insert( pItem );
- ItemToRowJob job( item, list.begin() );
- Walker(m_root , job );
- return job.GetResult();
+ ItemToRowJob job( item, list.begin() );
+ Walker(m_root , job );
+ return job.GetResult();
+ }
}
void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node)
void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
{
+ DestroyTree();
+
+ if (GetOwner()->GetModel()->IsIndexListModel())
+ {
+ m_count = -1 ;
+ return;
+ }
+
+ m_root = new wxDataViewTreeNode( NULL );
+ m_root->SetHasChildren(true);
+
//First we define a invalid item to fetch the top-level elements
wxDataViewItem item;
SortPrepare();
void wxDataViewMainWindow::DestroyTree()
{
- DestroyTreeHelper(m_root);
- m_root->SetSubTreeCount(0);
- m_count = 0 ;
+ if (m_root)
+ {
+ DestroyTreeHelper(m_root);
+ m_count = 0;
+ m_root = NULL;
+ }
}
void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
//Test whether the mouse is hovered on the tree item button
bool hover = false;
- if (GetOwner()->GetExpanderColumn() == col)
+ if ((m_root) && (GetOwner()->GetExpanderColumn() == col))
{
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
if( node!=NULL && node->HasChildren() )
//Process the event of user clicking the expander
bool expander = false;
- if (GetOwner()->GetExpanderColumn() == col)
+ if ((m_root) && (GetOwner()->GetExpanderColumn() == col))
{
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
if( node!=NULL && node->HasChildren() )
model->AddNotifier( m_notifier );
+ m_clientArea->DestroyTree();
+
m_clientArea->BuildTree(model);
m_clientArea->UpdateDisplay();
bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
{
wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column );
- if (ret == NULL)
+ if (!ret)
return false;
m_cols.Erase(ret);