X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8e3ca43b377fc5b5e0e1e0de67366878dc5eff5b..f01fbad837f6be9afed3e346b1b28dced163c9f5:/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp?ds=inline diff --git a/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp b/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp index 8aef1b7cba..4e7eea7069 100644 --- a/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp +++ b/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp @@ -19,10 +19,6 @@ // headers // --------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma implementation "treelistctrl.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -40,6 +36,7 @@ #include #include #include +#include #include "wx/treelistctrl.h" @@ -152,6 +149,7 @@ public: void DrawCurrent(); void AdjustDC(wxDC& dc); + void OnEraseBackground( wxEraseEvent& event ); void OnPaint( wxPaintEvent &event ); void OnMouse( wxMouseEvent &event ); void OnSetFocus( wxFocusEvent &event ); @@ -1072,12 +1070,13 @@ void wxTreeListTextCtrl::OnKillFocus( wxFocusEvent &event ) // wxTreeListHeaderWindow //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow,wxWindow); +IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow,wxWindow) BEGIN_EVENT_TABLE(wxTreeListHeaderWindow,wxWindow) - EVT_PAINT (wxTreeListHeaderWindow::OnPaint) - EVT_MOUSE_EVENTS (wxTreeListHeaderWindow::OnMouse) - EVT_SET_FOCUS (wxTreeListHeaderWindow::OnSetFocus) + EVT_ERASE_BACKGROUND (wxTreeListHeaderWindow::OnEraseBackground) + EVT_PAINT (wxTreeListHeaderWindow::OnPaint) + EVT_MOUSE_EVENTS (wxTreeListHeaderWindow::OnMouse) + EVT_SET_FOCUS (wxTreeListHeaderWindow::OnSetFocus) END_EVENT_TABLE() void wxTreeListHeaderWindow::Init() @@ -1110,7 +1109,7 @@ wxTreeListHeaderWindow::wxTreeListHeaderWindow( wxWindow *win, m_owner = owner; m_resizeCursor = new wxCursor(wxCURSOR_SIZEWE); - SetBackgroundColour(wxSystemSettings::GetSystemColour( + SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE)); } @@ -1136,7 +1135,7 @@ void wxTreeListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) dc->SetBrush( *wxTRANSPARENT_BRUSH ); - dc->SetPen( wxPen(wxSystemSettings::GetSystemColour( + dc->SetPen( wxPen(wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW), 1, wxSOLID)); dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) @@ -1161,7 +1160,7 @@ void wxTreeListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) - wxPen pen(wxSystemSettings::GetSystemColour( + wxPen pen(wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID); dc->SetPen( pen ); @@ -1190,33 +1189,42 @@ void wxTreeListHeaderWindow::AdjustDC(wxDC& dc) dc.SetDeviceOrigin( -x * xpix, 0 ); } + +void wxTreeListHeaderWindow::OnEraseBackground( wxEraseEvent& event ) +{ +} + void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { #ifdef __WXGTK__ - wxClientDC dc( this ); + wxClientDC real_dc( this ); #else - wxPaintDC dc( this ); + wxPaintDC real_dc( this ); #endif - PrepareDC( dc ); - AdjustDC( dc ); - - dc.BeginDrawing(); - - dc.SetFont( GetFont() ); + AdjustDC( real_dc ); // width and height of the entire header window int w, h; GetClientSize( &w, &h ); m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); + // Setup double buffering to eliminate the flicker + wxMemoryDC dc; + wxBitmap buffer(w, h); + dc.SelectObject(buffer); + dc.SetBackground(wxBrush(GetBackgroundColour())); + dc.Clear(); + + dc.BeginDrawing(); + dc.SetFont( GetFont() ); dc.SetBackgroundMode(wxTRANSPARENT); // do *not* use the listctrl colour for headers - one day we will have a // function to set it separately //dc.SetTextForeground( *wxBLACK ); dc.SetTextForeground(wxSystemSettings:: - GetSystemColour( wxSYS_COLOUR_WINDOWTEXT )); + GetColour( wxSYS_COLOUR_WINDOWTEXT )); int x = HEADER_OFFSET_X; @@ -1294,12 +1302,14 @@ void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { //DoDrawRect( &dc, x, HEADER_OFFSET_Y, more_w, h-2 ); wxRendererNative::Get().DrawHeaderButton( - this, dc, wxRect(x, HEADER_OFFSET_Y, more_w, h-3), + this, dc, wxRect(x, HEADER_OFFSET_Y, more_w, h-2), m_parent->IsEnabled() ? 0 : wxCONTROL_DISABLED); } - + // Finish up by drawing the buffer to the real dc dc.EndDrawing(); + dc.SelectObject(wxNullBitmap); + real_dc.DrawBitmap(buffer, 0, 0, false); } void wxTreeListHeaderWindow::DrawCurrent() @@ -1384,7 +1394,7 @@ void wxTreeListHeaderWindow::OnMouse( wxMouseEvent &event ) // end of the current column int xpos = 0; - // find the column where this event occured + // find the column where this event occurred int countCol = GetColumnCount(); for (int col = 0; col < countCol; col++) { @@ -1676,8 +1686,10 @@ wxTreeListItem *wxTreeListItem::HitTest(const wxPoint& point, } // check for image hit - if (theCtrl->m_imgWidth > 0) { + if (theCtrl->m_imgWidth > 0 && GetImage() != NO_IMAGE) { int imgX = m_x - theCtrl->m_imgWidth2; + if (HasPlus() && theCtrl->HasButtons()) + imgX += theCtrl->m_btnWidth + LINEATROOT; int imgY = y_mid - theCtrl->m_imgHeight2; if ((point.x >= imgX) && (point.x <= (imgX + theCtrl->m_imgWidth)) && (point.y >= imgY) && (point.y <= (imgY + theCtrl->m_imgHeight))) { @@ -1843,7 +1855,7 @@ void wxTreeListMainWindow::Init() m_hilightBrush = new wxBrush ( - wxSystemSettings::GetSystemColour + wxSystemSettings::GetColour ( wxSYS_COLOUR_HIGHLIGHT ), @@ -1852,7 +1864,7 @@ void wxTreeListMainWindow::Init() m_hilightUnfocusedBrush = new wxBrush ( - wxSystemSettings::GetSystemColour + wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNSHADOW ), @@ -1875,7 +1887,7 @@ void wxTreeListMainWindow::Init() m_underMouse = NULL; -#if defined( __WXMAC__ ) && __WXMAC_CARBON__ +#ifdef __WXMAC_CARBON__ m_normalFont.MacCreateThemeFont( kThemeViewsFont ) ; #else m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); @@ -1920,7 +1932,7 @@ bool wxTreeListMainWindow::Create(wxTreeListCtrl *parent, SetValidator( validator ); #endif - SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) ); + SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) ); #ifdef __WXMSW__ { @@ -2447,7 +2459,7 @@ wxTreeItemId wxTreeListMainWindow::DoInsertItem(const wxTreeItemId& parentId, if ( data != NULL ) { - data->SetId((long)item); + data->SetId((void*)item); } parent->Insert( item, previous ); @@ -2484,7 +2496,7 @@ wxTreeItemId wxTreeListMainWindow::AddRoot(const wxString& text, #endif if ( data != NULL ) { - data->SetId((long)m_anchor); + data->SetId((void*)m_anchor); } if (!HasFlag(wxTR_MULTIPLE)) @@ -2559,7 +2571,7 @@ wxTreeItemId wxTreeListMainWindow::AppendItem(const wxTreeItemId& parentId, void wxTreeListMainWindow::SendDeleteEvent(wxTreeListItem *item) { wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, m_owner->GetId() ); - event.SetItem((long) item); + event.SetItem((void*)item); event.SetEventObject( /*this*/m_owner ); m_owner->ProcessEvent( event ); } @@ -2636,7 +2648,7 @@ void wxTreeListMainWindow::Expand(const wxTreeItemId& itemId) return; wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, m_owner->GetId() ); - event.SetItem( (long) item ); + event.SetItem( (void*)item ); event.SetEventObject( /*this*/m_owner ); if ( m_owner->ProcessEvent( event ) && !event.IsAllowed() ) @@ -2682,7 +2694,7 @@ void wxTreeListMainWindow::Collapse(const wxTreeItemId& itemId) return; wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, m_owner->GetId() ); - event.SetItem( (long) item ); + event.SetItem( (void*)item ); event.SetEventObject( /*this*/m_owner ); if ( m_owner->ProcessEvent( event ) && !event.IsAllowed() ) { @@ -2860,8 +2872,8 @@ void wxTreeListMainWindow::SelectItem(const wxTreeItemId& itemId, } wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, m_owner->GetId() ); - event.SetItem( (long) item ); - event.SetOldItem( (long) m_current ); + event.SetItem( (void*)item ); + event.SetOldItem( (void*)m_current ); event.SetEventObject( /*this*/m_owner ); // TODO : Here we don't send any selection mode yet ! @@ -2920,7 +2932,7 @@ void wxTreeListMainWindow::SelectAll(bool extended_select) wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, m_owner->GetId() ); event.SetItem( GetRootItem() ); - event.SetOldItem( (long) m_current ); + event.SetOldItem( (void*) m_current ); event.SetEventObject( /*this*/m_owner ); // TODO : Here we don't send any selection mode yet ! @@ -3298,7 +3310,7 @@ void wxTreeListMainWindow::PaintItem(wxTreeListItem *item, wxDC& dc) if (item->IsSelected() && HasFlag(wxTR_FULL_ROW_HIGHLIGHT)) { dc.SetBrush(*(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush)); dc.SetPen(*wxBLACK_PEN); - colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT); + colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); } else { wxColour colBg; if (attr && attr->HasBackgroundColour()) { @@ -3364,7 +3376,7 @@ void wxTreeListMainWindow::PaintItem(wxTreeListItem *item, wxDC& dc) int width = wxMin(text_w+2, colwidth - text_x - x_colstart); dc.DrawRectangle(text_x-1, item->GetY() + offset, width, total_h-offset); dc.SetBackgroundMode(wxTRANSPARENT); - dc.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT)); + dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT)); }else{ dc.SetTextForeground(colText); } @@ -3785,7 +3797,7 @@ void wxTreeListMainWindow::OnChar( wxKeyEvent &event ) { wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, m_owner->GetId() ); - event.SetItem( (long) m_current); + event.SetItem( (void*) m_current); event.SetEventObject( /*this*/m_owner ); m_owner->GetEventHandler()->ProcessEvent( event ); } @@ -4056,7 +4068,7 @@ void wxTreeListMainWindow::Edit( const wxTreeItemId& item ) m_currentEdit = (wxTreeListItem*) item.m_pItem; wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, m_owner->GetId() ); - te.SetItem( (long) m_currentEdit); + te.SetItem( (void*) m_currentEdit); te.SetEventObject( /*this*/m_owner ); m_owner->GetEventHandler()->ProcessEvent( te ); @@ -4097,7 +4109,7 @@ void wxTreeListMainWindow::OnRenameAccept() { // TODO if the validator fails this causes a crash wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, m_owner->GetId() ); - le.SetItem( (long) m_currentEdit ); + le.SetItem( (void*)m_currentEdit ); le.SetEventObject( /*this*/m_owner ); le.SetLabel( m_renameRes ); m_owner->GetEventHandler()->ProcessEvent( le ); @@ -4117,6 +4129,9 @@ void wxTreeListMainWindow::OnMouse( wxMouseEvent &event ) int flags = 0; wxTreeListItem *item = m_anchor->HitTest(pt, this, flags, 0); wxTreeListItem *underMouse = item; +#if wxUSE_TOOLTIPS + bool underMouseChanged = (underMouse != m_underMouse) ; +#endif // wxUSE_TOOLTIPS if (underMouse && (flags & wxTREE_HITTEST_ONITEMBUTTON) && !event.LeftIsDown() && !m_isDragging && @@ -4143,6 +4158,25 @@ void wxTreeListMainWindow::OnMouse( wxMouseEvent &event ) RefreshLine( m_underMouse ); } +#if wxUSE_TOOLTIPS + // Determines what item we are hovering over and need a tooltip for + wxTreeItemId hoverItem = item; + + // We do not want a tooltip if we are dragging, or if the rename timer is running + if (underMouseChanged && hoverItem.IsOk() && !m_isDragging && (!m_renameTimer || !m_renameTimer->IsRunning())) + { + // Ask the tree control what tooltip (if any) should be shown + wxTreeEvent hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, GetId()); + hevent.SetItem(hoverItem); + hevent.SetEventObject(this); + + if ( GetEventHandler()->ProcessEvent(hevent) && hevent.IsAllowed() ) + { + SetToolTip(hevent.GetLabel()); + } + } +#endif + // we process left mouse up event (enables in-place edit), right down // (pass to the user code), left dbl click (activate item) and // dragging/moving events for items drag-and-drop @@ -4185,8 +4219,9 @@ void wxTreeListMainWindow::OnMouse( wxMouseEvent &event ) : wxEVT_COMMAND_TREE_BEGIN_DRAG; wxTreeEvent nevent( command,/*ALB*/ m_owner->GetId() ); - nevent.SetItem( (long) m_current); + nevent.SetItem( (void*)m_current); nevent.SetEventObject(/*this*/m_owner); // ALB + nevent.SetPoint(pt); // by default the dragging is not supported, the user code must // explicitly allow the event for it to take place @@ -4247,7 +4282,7 @@ void wxTreeListMainWindow::OnMouse( wxMouseEvent &event ) // generate the drag end event wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG,/*ALB*/m_owner->GetId()); - event.SetItem( (long) item ); + event.SetItem( (void*)item ); event.SetPoint( wxPoint(x, y) ); event.SetEventObject(/*this*/m_owner); @@ -4275,7 +4310,7 @@ void wxTreeListMainWindow::OnMouse( wxMouseEvent &event ) SetFocus(); wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, m_owner->GetId()); - nevent.SetItem( (long) item ); + nevent.SetItem( (void*)item ); int nx, ny; CalcScrolledPosition(x, y, &nx, &ny); nevent.SetPoint( wxPoint(nx, ny)); @@ -4342,7 +4377,7 @@ void wxTreeListMainWindow::OnMouse( wxMouseEvent &event ) // send activate event first wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, m_owner->GetId() ); - nevent.SetItem( (long) item ); + nevent.SetItem( (void*)item ); int nx, ny; CalcScrolledPosition(x, y, &nx, &ny); nevent.SetPoint( wxPoint(nx, ny) ); @@ -4590,10 +4625,11 @@ void wxTreeListMainWindow::SetFocus() // wxTreeListCtrl //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl, wxControl); +IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl, wxControl) BEGIN_EVENT_TABLE(wxTreeListCtrl, wxControl) EVT_SIZE(wxTreeListCtrl::OnSize) + EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY, wxTreeListCtrl::OnGetToolTip) END_EVENT_TABLE(); bool wxTreeListCtrl::Create(wxWindow *parent, wxWindowID id, @@ -4629,24 +4665,30 @@ void wxTreeListCtrl::CalculateAndSetHeaderHeight() h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT; // only update if changed - if ( h != m_headerHeight ) + if ( h != (int)m_headerHeight ) { - m_headerHeight = h; - //m_header_win->SetSize(m_header_win->GetSize().x, m_headerHeight); + m_headerHeight = (size_t)h; + m_header_win->SetSize(m_header_win->GetSize().x, m_headerHeight); } } } - -void wxTreeListCtrl::OnSize(wxSizeEvent& WXUNUSED(event)) +void wxTreeListCtrl::DoHeaderLayout() { int w, h; GetClientSize(&w, &h); - printf("%d (%d, %d)\n", m_headerHeight, w, h); if (m_header_win) + { m_header_win->SetSize(0, 0, w, m_headerHeight); + m_header_win->Refresh(false); + } if (m_main_win) m_main_win->SetSize(0, m_headerHeight + 1, w, h - m_headerHeight - 1); +} + +void wxTreeListCtrl::OnSize(wxSizeEvent& WXUNUSED(event)) +{ + DoHeaderLayout(); } @@ -4997,7 +5039,10 @@ wxString wxTreeListCtrl::GetColumnText(size_t column) const { return m_header_win->GetColumnText(column); } void wxTreeListCtrl::AddColumn(const wxTreeListColumnInfo& col) -{ m_header_win->AddColumn(col); } +{ + m_header_win->AddColumn(col); + DoHeaderLayout(); +} void wxTreeListCtrl::InsertColumn(size_t before, const wxTreeListColumnInfo& col) @@ -5063,3 +5108,11 @@ wxSize wxTreeListCtrl::DoGetBestSize() const // something is better than nothing... return wxSize(100,80); } + +// Process the tooltip event, to speed up event processing. +// Doesn't actually get a tooltip. +void wxTreeListCtrl::OnGetToolTip( wxTreeEvent &event ) +{ + event.Veto(); +} +