X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0d1c4edee3bc79b4f6bd33802f8858a0602141ab..936f635341e9b92b37db93cc7781d564babbe25f:/src/generic/datavgen.cpp diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 6fafd57a25..0d0b1ad120 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -63,7 +63,10 @@ static const int EXPANDER_MARGIN = 4; // wxDataViewHeaderWindow //----------------------------------------------------------------------------- -#define USE_NATIVE_HEADER_WINDOW 1 +// on wxMSW the header window (only that part however) can be made native! +#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) + #define USE_NATIVE_HEADER_WINDOW +#endif //Below is the compare stuff //For the generic implements, both the leaf nodes and the nodes are sorted for fast search when needed @@ -109,8 +112,7 @@ protected: void SendEvent(wxEventType type, unsigned int n); }; -// on wxMSW the header window (only that part however) can be made native! -#if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW +#ifdef USE_NATIVE_HEADER_WINDOW #define COLUMN_WIDTH_OFFSET 2 #define wxDataViewHeaderWindowMSW wxDataViewHeaderWindow @@ -138,14 +140,16 @@ public: // the column count virtual void UpdateDisplay(); + virtual void OnInternalIdle(); + // called Refresh afterwards virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL); - - virtual bool CanApplyThemeBorder() const { return false; } + + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } protected: virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); - + virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags); wxSize DoGetBestSize() const; @@ -154,9 +158,10 @@ protected: wxDataViewColumn *GetColumnFromHeader(NMHEADER *nmHDR) { return GetColumn(GetColumnIdxFromHeader(nmHDR)); } - - int m_scrollOffsetX; - int m_buttonHeight; + + int m_scrollOffsetX; + int m_buttonHeight; + bool m_delayedUpdate; private: DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW) @@ -745,7 +750,7 @@ bool wxDataViewTextRendererAttr::Render( wxRect cell, wxDC *dc, int WXUNUSED(sta colour = dc->GetTextForeground(); dc->SetTextForeground( m_attr.GetColour() ); } - + if (m_attr.GetBold() || m_attr.GetItalic()) { font = dc->GetFont(); @@ -757,22 +762,22 @@ bool wxDataViewTextRendererAttr::Render( wxRect cell, wxDC *dc, int WXUNUSED(sta 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 @@ -1144,6 +1149,8 @@ wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *c SetTitle(title); SetFlags(flags); + m_autosize = width < 0; // TODO + Init(width < 0 ? wxDVC_DEFAULT_WIDTH : width); } @@ -1260,7 +1267,7 @@ void wxDataViewHeaderWindowBase::SendEvent(wxEventType type, unsigned int n) parent->GetEventHandler()->ProcessEvent(le); } -#if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW +#ifdef USE_NATIVE_HEADER_WINDOW #ifndef HDS_DRAGDROP #define HDS_DRAGDROP 0x0040 @@ -1281,6 +1288,7 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, m_owner = parent; m_scrollOffsetX = 0; + m_delayedUpdate = false; m_buttonHeight = wxRendererNative::Get().GetHeaderButtonHeight( this ); int x = pos.x == wxDefaultCoord ? 0 : pos.x, @@ -1296,10 +1304,10 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, // create the native WC_HEADER window: WXHWND hwndParent = (HWND)parent->GetHandle(); WXDWORD msStyle = WS_CHILD | HDS_DRAGDROP | HDS_BUTTONS | HDS_HORZ | HDS_HOTTRACK | HDS_FULLDRAG; - + if ( m_isShown ) msStyle |= WS_VISIBLE; - + m_hWnd = CreateWindowEx(0, WC_HEADER, (LPCTSTR) NULL, @@ -1322,7 +1330,7 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, // the following is required to get the default win's font for // header windows and must be done befor sending the HDM_LAYOUT msg SetFont(GetFont()); - + return true; } @@ -1333,7 +1341,16 @@ wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow() wxSize wxDataViewHeaderWindowMSW::DoGetBestSize() const { - return wxSize(80, m_buttonHeight ); + return wxSize( 80, m_buttonHeight+2 ); +} + +void wxDataViewHeaderWindowMSW::OnInternalIdle() +{ + if (m_delayedUpdate) + { + m_delayedUpdate = false; + UpdateDisplay(); + } } void wxDataViewHeaderWindowMSW::UpdateDisplay() @@ -1456,10 +1473,13 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA case HDN_ENDDRAG: // user has finished reordering a column { - // TODO: How to query the new position here? + wxDataViewColumn *col = GetColumn(nmHDR->iItem); + unsigned int new_pos = nmHDR->pitem->iOrder; + m_owner->ColumnMoved( col, new_pos ); + m_delayedUpdate = true; } break; - + case HDN_ITEMCHANGING: if (nmHDR->pitem != NULL && (nmHDR->pitem->mask & HDI_WIDTH) != 0) @@ -1583,7 +1603,7 @@ void wxDataViewHeaderWindowMSW::ScrollWindow(int dx, int WXUNUSED(dy), const wxRect * WXUNUSED(rect)) { m_scrollOffsetX += dx; - + GetParent()->Layout(); } @@ -1948,6 +1968,8 @@ wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID i SetBackgroundColour( *wxWHITE ); + SetBackgroundStyle(wxBG_STYLE_CUSTOM); + m_penRule = wxPen(GetRuleColour(), 1, wxSOLID); //Here I compose a pen can draw black lines, maybe there are something system colour to use @@ -2114,7 +2136,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxVariant value; wxDataViewTreeNode *node = NULL; wxDataViewItem dataitem; - + if (m_root) { node = GetTreeNodeByRow(item); @@ -2133,7 +2155,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) model->GetValue( value, dataitem, col->GetModelColumn()); cell->SetValue( value ); - + if (cell->GetWantsAttr()) { wxDataViewItemAttr attr; @@ -2151,7 +2173,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) if ((m_root) && (col == expander)) { indent = node->GetIndentLevel(); - + //Calculate the indent first indent = cell_rect.x + GetOwner()->GetIndent() * indent; @@ -2179,7 +2201,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // 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 + // Yes, if the node does not have any child, it must be a leaf which // mean that it is a temporarily created by GetTreeNodeByRow } @@ -2348,7 +2370,7 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData UpdateDisplay(); return true; } - + SortPrepare(); wxDataViewTreeNode * node; @@ -2389,7 +2411,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, m_currentRow = m_count - 1; m_selection.Empty(); - + UpdateDisplay(); return true; @@ -2501,10 +2523,10 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i bool wxDataViewMainWindow::Cleared() { DestroyTree(); - + SortPrepare(); BuildTree( GetOwner()->GetModel() ); - + UpdateDisplay(); return true; @@ -3375,16 +3397,8 @@ void wxDataViewMainWindow::DestroyTree() void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) { - if (event.GetKeyCode() == WXK_TAB) - { - wxNavigationKeyEvent nevent; - nevent.SetWindowChange( event.ControlDown() ); - nevent.SetDirection( !event.ShiftDown() ); - nevent.SetEventObject( GetParent()->GetParent() ); - nevent.SetCurrentFocus( m_parent ); - if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) - return; - } + if ( HandleAsNavigationKey(event) ) + return; // no item -> nothing to do if (!HasCurrentRow()) @@ -3691,10 +3705,22 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) } // notify cell about right click - // cell->... - - // Allow generation of context menu event - event.Skip(); + wxVariant value; + model->GetValue( value, item, col->GetModelColumn() ); + cell->SetValue( value ); + wxRect cell_rect( xpos, current * m_lineHeight, + col->GetWidth(), m_lineHeight ); + if (!cell->RightClick( event.GetPosition(), cell_rect, model, item, col->GetModelColumn())) + { + wxWindow *parent = GetParent(); + wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId()); + le.SetItem( item ); + le.SetEventObject(parent); + le.SetModel(GetOwner()->GetModel()); + le.SetValue(value); + + parent->GetEventHandler()->ProcessEvent(le); + } } else if (event.MiddleDown()) { @@ -3898,7 +3924,7 @@ bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) model->AddNotifier( m_notifier ); m_clientArea->DestroyTree(); - + m_clientArea->BuildTree(model); m_clientArea->UpdateDisplay(); @@ -3965,6 +3991,15 @@ wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const return NULL; } +void wxDataViewCtrl::ColumnMoved( wxDataViewColumn* col, unsigned int new_pos ) +{ + if (new_pos > m_cols.GetCount()) return; + m_cols.DeleteObject( col ); + m_cols.Insert( new_pos, col ); + + m_clientArea->UpdateDisplay(); +} + bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) { wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column );