X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4bae66a8deb5432ff0426f2b0de60f13e3bdb0bf..d65381ac3415e9be42a378511e91755eb114b72b:/src/generic/datavgen.cpp?ds=sidebyside diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index c12b0bb688..a21401fd6f 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -154,6 +154,7 @@ protected: { return GetColumn(GetColumnIdxFromHeader(nmHDR)); } int m_scrollOffsetX; + int m_buttonHeight; private: DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW) @@ -404,7 +405,7 @@ int LINKAGEMODE wxGenericTreeModelItemCmp( void ** id1, void ** id2) WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection, WXDLLIMPEXP_ADV); WX_DECLARE_LIST(wxDataViewItem, ItemList); -WX_DEFINE_LIST(ItemList); +WX_DEFINE_LIST(ItemList) class wxDataViewMainWindow: public wxWindow { @@ -424,8 +425,11 @@ public: bool Cleared(); void Resort() { - SortPrepare(); - m_root->Resort(); + if (m_root) + { + SortPrepare(); + m_root->Resort(); + } UpdateDisplay(); } @@ -606,6 +610,8 @@ wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, m_dc = NULL; m_align = align; m_mode = mode; + m_wantsAttr = false; + m_hasAttr = false; } wxDataViewRenderer::~wxDataViewRenderer() @@ -712,6 +718,60 @@ wxSize wxDataViewTextRenderer::GetSize() const 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 // --------------------------------------------------------- @@ -1192,6 +1252,13 @@ void wxDataViewHeaderWindowBase::SendEvent(wxEventType type, unsigned int n) #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); @@ -1203,19 +1270,20 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, { m_owner = parent; - m_scrollOffsetX = 0;; + m_scrollOffsetX = 0; + m_buttonHeight = wxRendererNative::Get().GetHeaderButtonHeight( this ) + 10; int x = pos.x == wxDefaultCoord ? 0 : pos.x, y = pos.y == wxDefaultCoord ? 0 : pos.y, w = size.x == wxDefaultCoord ? 1 : size.x, - h = size.y == wxDefaultCoord ? 22 : size.y; + h = size.y == wxDefaultCoord ? m_buttonHeight : size.y; if ( !CreateControl(parent, id, pos, size, 0, wxDefaultValidator, name) ) return false; // 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; @@ -1253,16 +1321,9 @@ wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow() wxSize wxDataViewHeaderWindowMSW::DoGetBestSize() const { - return wxSize(80, 22); + 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 @@ -1321,7 +1382,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay() default: // such alignment is not allowed for the column header! - wxFAIL; + break; // wxFAIL; } SendMessage((HWND)m_hWnd, HDM_INSERTITEM, @@ -1496,7 +1557,8 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA return true; } -void wxDataViewHeaderWindowMSW::ScrollWindow(int dx, int dy, const wxRect *rect ) +void wxDataViewHeaderWindowMSW::ScrollWindow(int dx, int WXUNUSED(dy), + const wxRect * WXUNUSED(rect)) { m_scrollOffsetX += dx; @@ -1507,7 +1569,8 @@ void wxDataViewHeaderWindowMSW::DoSetSize(int x, int y, int w, int h, int f) { - wxControl::DoSetSize( x+m_scrollOffsetX, y, w-m_scrollOffsetX, h, f ); + // TODO: why is there a border + 2px around it? + wxControl::DoSetSize( x+m_scrollOffsetX+1, y+1, w-m_scrollOffsetX-2, h-2, f ); } #else // !defined(__WXMSW__) @@ -1838,7 +1901,7 @@ END_EVENT_TABLE() wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxString &name ) : - wxWindow( parent, id, pos, size, wxWANTS_CHARS, name ), + wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE, name ), m_selection( wxDataViewSelectionCmp ) { @@ -2228,7 +2291,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) 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 @@ -2348,25 +2411,46 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { // 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; @@ -2391,9 +2475,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) } 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 @@ -2790,9 +2876,16 @@ private: 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 @@ -2865,9 +2958,16 @@ private: 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 ) @@ -3054,7 +3154,19 @@ wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, const wxD 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 @@ -3108,26 +3220,33 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) 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) @@ -3162,6 +3281,17 @@ void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataVie 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(); @@ -3186,9 +3316,12 @@ void DestroyTreeHelper( wxDataViewTreeNode * node ) 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 ) @@ -3328,7 +3461,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &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() ) @@ -3453,7 +3586,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) //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() ) @@ -3620,7 +3753,7 @@ wxDataViewItem wxDataViewMainWindow::GetSelection() const //----------------------------------------------------------------------------- // wxDataViewCtrl //----------------------------------------------------------------------------- -WX_DEFINE_LIST(wxDataViewColumnList); +WX_DEFINE_LIST(wxDataViewColumnList) IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) @@ -3644,7 +3777,7 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, long style, const wxValidator& validator ) { if (!wxControl::Create( parent, id, pos, size, - style | wxScrolledWindowStyle|wxSUNKEN_BORDER, validator)) + style | wxScrolledWindowStyle|wxBORDER_SUNKEN, validator)) return false; SetInitialSize(size); @@ -3715,6 +3848,8 @@ bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) model->AddNotifier( m_notifier ); + m_clientArea->DestroyTree(); + m_clientArea->BuildTree(model); m_clientArea->UpdateDisplay(); @@ -3784,7 +3919,7 @@ wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) { wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column ); - if (ret == NULL) + if (!ret) return false; m_cols.Erase(ret);