X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/33328cd8828baafa97e8623e005b471486b61cc7..9859d369b49e35a1cad0f760173e165f974fb6cb:/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp diff --git a/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp b/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp index 054a06683d..1fbe0b94e9 100644 --- a/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp +++ b/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp @@ -18,10 +18,6 @@ // headers // --------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma implementation "treelistctrl.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -123,7 +119,14 @@ protected: // total width of the columns int m_total_col_width; +#if wxCHECK_VERSION_FULL(2, 7, 0, 1) + // which col header is currently highlighted with mouse-over + int m_hotTrackCol; + int XToCol(int x); + void RefreshColLabel(int col); +#endif + public: wxTreeListHeaderWindow(); @@ -1056,6 +1059,7 @@ void wxTreeListHeaderWindow::Init() m_isDragging = false; m_dirty = false; m_total_col_width = 0; + m_hotTrackCol = -1; } wxTreeListHeaderWindow::wxTreeListHeaderWindow() @@ -1112,7 +1116,7 @@ void wxTreeListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) #if defined( __WXMAC__ ) - wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID ); + pen = wxPen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID ); #endif dc->SetPen( pen ); dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) @@ -1148,7 +1152,8 @@ void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) PrepareDC( dc ); AdjustDC( dc ); - dc.SetFont( GetFont() ); + + int x = HEADER_OFFSET_X; // width and height of the entire header window int w, h; @@ -1156,6 +1161,48 @@ void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); dc.SetBackgroundMode(wxTRANSPARENT); +#if wxCHECK_VERSION_FULL(2, 7, 0, 1) + int numColumns = GetColumnCount(); + for ( int i = 0; i < numColumns && x < w; i++ ) + { + if (!IsColumnShown (i)) continue; // do next column if not shown + + wxHeaderButtonParams params; + + // TODO: columnInfo should have label colours... + params.m_labelColour = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); + params.m_labelFont = GetFont(); + + wxTreeListColumnInfo& column = GetColumn(i); + int wCol = column.GetWidth(); + int flags = 0; + wxRect rect(x, 0, wCol, h); + x += wCol; + + if ( i == m_hotTrackCol) + flags |= wxCONTROL_CURRENT; + + params.m_labelText = column.GetText(); + params.m_labelAlignment = column.GetAlignment(); + + int image = column.GetImage(); + wxImageList* imageList = m_owner->GetImageList(); + if ((image != -1) && imageList) + params.m_labelBitmap = imageList->GetBitmap(image); + + wxRendererNative::Get().DrawHeaderButton(this, dc, rect, flags, + wxHDR_SORT_ICON_NONE, ¶ms); + } + + if (x < w) { + wxRect rect(x, 0, w-x, h); + wxRendererNative::Get().DrawHeaderButton(this, dc, rect); + } + +#else // not 2.7.0.1+ + + dc.SetFont( GetFont() ); + // do *not* use the listctrl colour for headers - one day we will have a // function to set it separately //dc.SetTextForeground( *wxBLACK ); @@ -1165,12 +1212,10 @@ void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.SetTextForeground (wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT )); #endif - int x = HEADER_OFFSET_X; - int numColumns = GetColumnCount(); for ( int i = 0; i < numColumns && x < w; i++ ) { - if (!IsColumnShown (i)) continue; // do next colume if not shown + if (!IsColumnShown (i)) continue; // do next column if not shown wxTreeListColumnInfo& column = GetColumn(i); int wCol = column.GetWidth(); @@ -1241,7 +1286,7 @@ void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxRendererNative::GetDefault().DrawHeaderButton (this, dc, rect); #endif } - +#endif // 2.7.0.1 } void wxTreeListHeaderWindow::DrawCurrent() @@ -1270,6 +1315,46 @@ void wxTreeListHeaderWindow::DrawCurrent() dc.SetBrush (wxNullBrush); } +#if wxCHECK_VERSION_FULL(2, 7, 0, 1) +int wxTreeListHeaderWindow::XToCol(int x) +{ + int colLeft = 0; + int numColumns = GetColumnCount(); + for ( int col = 0; col < numColumns; col++ ) + { + if (!IsColumnShown(col)) continue; + wxTreeListColumnInfo& column = GetColumn(col); + + if ( x < (colLeft + column.GetWidth()) ) + return col; + + colLeft += column.GetWidth(); + } + return -1; +} + + +void wxTreeListHeaderWindow::RefreshColLabel(int col) +{ + if ( col >= GetColumnCount() ) + return; + + int x = 0; + int width = 0; + int idx = 0; + do { + if (!IsColumnShown(idx)) continue; + wxTreeListColumnInfo& column = GetColumn(idx); + x += width; + width = column.GetWidth(); + } while (++idx <= col); + + m_owner->CalcScrolledPosition(x, 0, &x, NULL); + RefreshRect(wxRect(x, 0, width, GetSize().GetHeight())); +} +#endif + + void wxTreeListHeaderWindow::OnMouse (wxMouseEvent &event) { // we want to work with logical coords @@ -1277,6 +1362,32 @@ void wxTreeListHeaderWindow::OnMouse (wxMouseEvent &event) { m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); int y = event.GetY(); +#if wxCHECK_VERSION_FULL(2, 7, 0, 1) + if ( event.Moving() ) + { + int col = XToCol(x); + if ( col != m_hotTrackCol ) + { + // Refresh the col header so it will be painted with hot tracking + // (if supported by the native renderer.) + RefreshColLabel(col); + + // Also refresh the old hot header + if ( m_hotTrackCol >= 0 ) + RefreshColLabel(m_hotTrackCol); + + m_hotTrackCol = col; + } + } + + if ( event.Leaving() && m_hotTrackCol >= 0 ) + { + // Leaving the window so clear any hot tracking indicator that may be present + RefreshColLabel(m_hotTrackCol); + m_hotTrackCol = -1; + } +#endif + if (m_isDragging) { SendListEvent (wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition()); @@ -1741,8 +1852,6 @@ bool wxTreeListMainWindow::Create (wxTreeListCtrl *parent, const wxString& name) { #ifdef __WXMAC__ - if (style & wxTR_HAS_BUTTONS) style |= wxTR_MAC_BUTTONS; - if (style & wxTR_HAS_BUTTONS) style &= ~wxTR_HAS_BUTTONS; style &= ~wxTR_LINES_AT_ROOT; style |= wxTR_NO_LINES; @@ -2560,7 +2669,7 @@ void wxTreeListMainWindow::SelectItem (const wxTreeItemId& itemId, } void wxTreeListMainWindow::SelectAll() { - wxCHECK_RET (HasFlag(wxTR_MULTIPLE), _T("invalid tree style")); + wxCHECK_RET (HasFlag(wxTR_MULTIPLE), _T("invalid tree style, must have wxTR_MULTIPLE style to select all items")); // send event to user code wxTreeEvent event (wxEVT_COMMAND_TREE_SEL_CHANGING, m_owner->GetId()); @@ -2581,6 +2690,7 @@ void wxTreeListMainWindow::SelectAll() { wxTreeItemId root = GetRootItem(); wxTreeListItem *first = (wxTreeListItem *)GetFirstChild (root, cookie).m_pItem; wxTreeListItem *last = (wxTreeListItem *)GetLastChild (root, cookie).m_pItem; + if (!first || !last) return; if (!TagAllChildrenUntilLast (first, last)) { TagNextChildren (first, last); } @@ -2911,24 +3021,34 @@ void wxTreeListMainWindow::PaintItem (wxTreeListItem *item, wxDC& dc) { #endif // !__WXMAC__ dc.SetTextForeground (colTextHilight); }else if (item->IsSelected()) { +#if defined(__WXGTK2__) || defined(__WXMAC__) + int flags = wxCONTROL_SELECTED; + if (m_hasFocus) + { + flags |= wxCONTROL_FOCUSED; +#ifdef __WXMAC__ + dc.SetTextForeground( *wxWHITE ); +#endif + } + wxRendererNative::GetDefault().DrawItemSelectionRect( m_owner, dc, wxRect( 0, item->GetY() + off_h, total_w, total_h - off_h ), flags); +#else if (!m_isDragging && m_hasFocus) { dc.SetBrush (*m_hilightBrush); -#ifndef __WXMAC__ // don't draw rect outline if we already have the background color dc.SetPen (*wxBLACK_PEN); -#endif // !__WXMAC__ }else{ dc.SetBrush (*m_hilightUnfocusedBrush); -#ifndef __WXMAC__ // don't draw rect outline if we already have the background color dc.SetPen (*wxTRANSPARENT_PEN); -#endif // !__WXMAC__ } dc.SetTextForeground (colTextHilight); +#endif // defined(__WXGTK2__) || defined(__WXMAC__) }else if (item == m_curItem) { dc.SetPen (m_hasFocus? *wxBLACK_PEN: *wxTRANSPARENT_PEN); }else{ dc.SetTextForeground (colText); } +#if !defined(__WXGTK2__) && !defined(__WXMAC__) dc.DrawRectangle (0, item->GetY() + off_h, total_w, total_h - off_h); +#endif }else{ dc.SetTextForeground (colText); } @@ -2989,24 +3109,34 @@ void wxTreeListMainWindow::PaintItem (wxTreeListItem *item, wxDC& dc) { #endif // !__WXMAC__ dc.SetTextForeground (colTextHilight); }else if (item->IsSelected()) { +#if defined(__WXGTK2__) || defined(__WXMAC__) + int flags = wxCONTROL_SELECTED; + if (m_hasFocus) + { + flags |= wxCONTROL_FOCUSED; +#ifdef __WXMAC__ + dc.SetTextForeground( *wxWHITE ); +#endif + } + wxRendererNative::GetDefault().DrawItemSelectionRect( m_owner, dc, wxRect( 0, item->GetY() + off_h, total_w, total_h - off_h ), flags); +#else if (!m_isDragging && m_hasFocus) { dc.SetBrush (*m_hilightBrush); -#ifndef __WXMAC__ // don't draw rect outline if we already have the background color dc.SetPen (*wxBLACK_PEN); -#endif // !__WXMAC__ }else{ dc.SetBrush (*m_hilightUnfocusedBrush); -#ifndef __WXMAC__ // don't draw rect outline if we already have the background color - dc.SetPen (*wxTRANSPARENT_PEN); -#endif // !__WXMAC__ + dc.SetPen (*wxTRANSPARENT_PEN); } dc.SetTextForeground (colTextHilight); +#endif // defined(__WXGTK2__) || defined(__WXMAC__) }else if (item == m_curItem) { dc.SetPen (m_hasFocus? *wxBLACK_PEN: *wxTRANSPARENT_PEN); }else{ dc.SetTextForeground (colText); } +#if !defined(__WXGTK2__) && !defined(__WXMAC__) dc.DrawRectangle (text_x, item->GetY() + off_h, text_w, total_h - off_h); +#endif }else{ dc.SetTextForeground (colText); } @@ -3470,7 +3600,7 @@ void wxTreeListMainWindow::OnChar (wxKeyEvent &event) { default: if (event.GetKeyCode() >= (int)' ') { if (!m_findTimer->IsRunning()) m_findStr.Clear(); - m_findStr.Append (event.GetKeyCode()); + m_findStr.Append ((char)event.GetKeyCode()); m_findTimer->Start (FIND_TIMER_TICKS, wxTIMER_ONE_SHOT); wxTreeItemId prev = m_curItem? (wxTreeItemId*)m_curItem: (wxTreeItemId*)NULL; while (true) { @@ -3680,6 +3810,7 @@ void wxTreeListMainWindow::OnMouse (wxMouseEvent &event) { #else nevent.SetItem (item); // the item the drag is ended #endif + nevent.SetPoint (p); nevent.Veto(); // dragging must be explicit allowed! m_owner->GetEventHandler()->ProcessEvent (nevent); @@ -4165,12 +4296,15 @@ bool wxTreeListCtrl::Create(wxWindow *parent, wxWindowID id, void wxTreeListCtrl::CalculateAndSetHeaderHeight() { if (m_header_win) { - + int h; +#if wxCHECK_VERSION_FULL(2, 7, 0, 1) + h = wxRendererNative::Get().GetHeaderButtonHeight(m_header_win); +#else // we use 'g' to get the descent, too - int w, h, d; + int w, d; m_header_win->GetTextExtent(_T("Hg"), &w, &h, &d); h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT; - +#endif // only update if changed if (h != m_headerHeight) { m_headerHeight = h; @@ -4502,8 +4636,7 @@ void wxTreeListCtrl::ScrollTo(const wxTreeItemId& item) wxTreeItemId wxTreeListCtrl::HitTest(const wxPoint& pos, int& flags, int& column) { - wxPoint p = m_main_win->ScreenToClient (ClientToScreen (pos)); - return m_main_win->HitTest (p, flags, column); + return m_main_win->HitTest (pos, flags, column); } bool wxTreeListCtrl::GetBoundingRect(const wxTreeItemId& item, wxRect& rect, @@ -4548,6 +4681,18 @@ int wxTreeListCtrl::GetColumnCount() const void wxTreeListCtrl::SetColumnWidth(int column, int width) { + if (width == wxLIST_AUTOSIZE_USEHEADER) + { + wxFont font = m_header_win->GetFont(); + m_header_win->GetTextExtent(m_header_win->GetColumnText(column), &width, NULL, NULL, NULL, font.Ok()? &font: NULL); + //search wxTreeListHeaderWindow::OnPaint to understand this: + width += 2*EXTRA_WIDTH + MARGIN; + } + else if (width == wxLIST_AUTOSIZE) + { + width = m_main_win->GetBestColumnWidth(column); + } + m_header_win->SetColumnWidth (column, width); m_header_win->Refresh(); }