From 0659e7ee61824b55b986995edabf55f0111376ae Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 18 Dec 1998 10:19:07 +0000 Subject: [PATCH] Tried to add sorting to wxTreeCtrl minor fixes to radiobutton git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1233 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dirdlg.h | 2 +- include/wx/generic/dirdlgg.h | 44 ++------- src/generic/dirdlgg.cpp | 75 ++++++++++++++- src/generic/treectrl.cpp | 176 ++++++++++++++++++++++------------- src/gtk.inc | 2 +- src/gtk/radiobut.cpp | 3 + src/gtk1/radiobut.cpp | 3 + 7 files changed, 197 insertions(+), 108 deletions(-) diff --git a/include/wx/dirdlg.h b/include/wx/dirdlg.h index b7eddfd094..6be23181a9 100644 --- a/include/wx/dirdlg.h +++ b/include/wx/dirdlg.h @@ -6,7 +6,7 @@ #elif defined(__WXMOTIF__) #include "wx/generic/dirdlgg.h" #elif defined(__WXGTK__) -#include "wx/gtk/dirdlg.h" +#include "wx/generic/dirdlgg.h" #elif defined(__WXQT__) #include "wx/qt/dirdlg.h" #elif defined(__WXMAC__) diff --git a/include/wx/generic/dirdlgg.h b/include/wx/generic/dirdlgg.h index 23b5997987..c70aedf6eb 100644 --- a/include/wx/generic/dirdlgg.h +++ b/include/wx/generic/dirdlgg.h @@ -58,51 +58,19 @@ //#include "wx/checkbox.h" #include "wx/treectrl.h" -WXDLLEXPORT_DATA(extern const char*) wxFileSelectorPromptStr; - //----------------------------------------------------------------------------- -// wxDirItemData +// data //----------------------------------------------------------------------------- -class wxDirItemData : public wxTreeItemData -{ -public: - wxDirItemData(wxString& path, wxString& name); - ~wxDirItemData(); - bool HasSubDirs(); - wxString *m_path, *m_name; - bool m_isHidden; - bool m_hasSubDirs; -}; +WXDLLEXPORT_DATA(extern const char*) wxFileSelectorPromptStr; //----------------------------------------------------------------------------- -// wxDirCtrl +// classes //----------------------------------------------------------------------------- -class wxDirCtrl: public wxTreeCtrl -{ - DECLARE_DYNAMIC_CLASS(wxDirCtrl) - - public: - bool m_showHidden; - wxTreeItemId m_rootId; - - wxDirCtrl(void); - wxDirCtrl(wxWindow *parent, const wxWindowID id = -1, - const wxString &dir = "/", - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - const long style = wxTR_HAS_BUTTONS, - const wxString& name = "wxTreeCtrl" ); - void OnExpandItem( const wxTreeEvent &event ); - void OnCollapseItem( const wxTreeEvent &event ); - void ShowHidden( const bool yesno ); - DECLARE_EVENT_TABLE() - protected: - void CreateItems(const wxTreeItemId &parent); - void SetupSections(void); - wxArrayString m_paths, m_names; -}; +class wxDirItemData; +class wxDirCtrl; +class wxDirDialog; //----------------------------------------------------------------------------- // wxDirDialog diff --git a/src/generic/dirdlgg.cpp b/src/generic/dirdlgg.cpp index b4b93e0035..5f23be0681 100644 --- a/src/generic/dirdlgg.cpp +++ b/src/generic/dirdlgg.cpp @@ -56,6 +56,34 @@ static char * icon1_xpm[] = { " ", " "}; +/* XPM */ +static char * icon2_xpm[] = { +/* width height ncolors chars_per_pixel */ +"16 16 6 1", +/* colors */ +" s None c None", +". c #000000", +"+ c #c0c0c0", +"@ c #808080", +"# c #ffff00", +"$ c #ffffff", +/* pixels */ +" ", +" @@@@@ ", +" @$$$$$@ ", +" @$#+#+#$@@@@@@ ", +" @$+#+#+$$$$$$@.", +" @$#+#+#+#+#+#@.", +"@@@@@@@@@@@@@#@.", +"@$$$$$$$$$$@@+@.", +"@$#+#+#+#+##.@@.", +" @$#+#+#+#+#+.@.", +" @$+#+#+#+#+#.@.", +" @$+#+#+#+##@..", +" @@@@@@@@@@@@@.", +" .............", +" ", +" "}; static const int ID_DIRCTRL = 1000; static const int ID_TEXTCTRL = 1001; @@ -68,6 +96,50 @@ static const int ID_NEW = 1004; // wxDirItemData //----------------------------------------------------------------------------- +class wxDirItemData : public wxTreeItemData +{ +public: + wxDirItemData(wxString& path, wxString& name); + ~wxDirItemData(); + bool HasSubDirs(); + wxString *m_path, *m_name; + bool m_isHidden; + bool m_hasSubDirs; +}; + +//----------------------------------------------------------------------------- +// wxDirCtrl +//----------------------------------------------------------------------------- + +class wxDirCtrl: public wxTreeCtrl +{ + DECLARE_DYNAMIC_CLASS(wxDirCtrl) + + public: + bool m_showHidden; + wxTreeItemId m_rootId; + + wxDirCtrl(void); + wxDirCtrl(wxWindow *parent, const wxWindowID id = -1, + const wxString &dir = "/", + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + const long style = wxTR_HAS_BUTTONS, + const wxString& name = "wxTreeCtrl" ); + void OnExpandItem( const wxTreeEvent &event ); + void OnCollapseItem( const wxTreeEvent &event ); + void ShowHidden( const bool yesno ); + DECLARE_EVENT_TABLE() + protected: + void CreateItems(const wxTreeItemId &parent); + void SetupSections(void); + wxArrayString m_paths, m_names; +}; + +//----------------------------------------------------------------------------- +// wxDirItemData +//----------------------------------------------------------------------------- + wxDirItemData::wxDirItemData(wxString& path, wxString& name) { m_path = new wxString(path); @@ -117,6 +189,7 @@ wxDirCtrl::wxDirCtrl(wxWindow *parent, const wxWindowID id, const wxString &WXUN { m_imageListNormal = new wxImageList(16, 16, TRUE); m_imageListNormal->Add(wxICON(icon1)); + m_imageListNormal->Add(wxICON(icon2)); SetImageList(m_imageListNormal); m_showHidden = FALSE; @@ -157,7 +230,7 @@ void wxDirCtrl::CreateItems(const wxTreeItemId &parent) for (unsigned int i=0; im_hasSubDirs) SetItemHasChildren(id); } } diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index 7231ed7c68..7d29b52f64 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -28,6 +28,7 @@ #include "wx/dynarray.h" #include "wx/dcclient.h" #include "wx/imaglist.h" +#include "wx/msgdlg.h" // ----------------------------------------------------------------------------- // array types @@ -873,40 +874,40 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId) void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item) { - wxGenericTreeItem *gitem = item.m_pItem; + wxGenericTreeItem *gitem = item.m_pItem; - int item_y = gitem->GetY(); + int item_y = gitem->GetY(); - int start_x = 0; - int start_y = 0; - ViewStart( &start_x, &start_y ); - start_y *= 10; + int start_x = 0; + int start_y = 0; + ViewStart( &start_x, &start_y ); + start_y *= 10; - if (item_y < start_y+3) - { - int x = 0; - int y = 0; - m_anchor->GetSize( x, y ); - y += 2*m_lineHeight; - int x_pos = GetScrollPos( wxHORIZONTAL ); - SetScrollbars( 10, 10, x/10, y/10, x_pos, item_y/10 ); - return; - } + if (item_y < start_y+3) + { + int x = 0; + int y = 0; + m_anchor->GetSize( x, y ); + y += 2*m_lineHeight; + int x_pos = GetScrollPos( wxHORIZONTAL ); + SetScrollbars( 10, 10, x/10, y/10, x_pos, item_y/10 ); + return; + } - int w = 0; - int h = 0; - GetClientSize( &w, &h ); + int w = 0; + int h = 0; + GetClientSize( &w, &h ); - if (item_y > start_y+h-26) - { - int x = 0; - int y = 0; - m_anchor->GetSize( x, y ); - y += 2*m_lineHeight; - int x_pos = GetScrollPos( wxHORIZONTAL ); - SetScrollbars( 10, 10, x/10, y/10, x_pos, (item_y-h+30)/10 ); - return; - } + if (item_y > start_y+h-26) + { + int x = 0; + int y = 0; + m_anchor->GetSize( x, y ); + y += 2*m_lineHeight; + int x_pos = GetScrollPos( wxHORIZONTAL ); + SetScrollbars( 10, 10, x/10, y/10, x_pos, (item_y-h+30)/10 ); + return; + } } void wxTreeCtrl::ScrollTo(const wxTreeItemId& WXUNUSED(item)) @@ -919,25 +920,52 @@ wxTextCtrl *wxTreeCtrl::EditLabel( const wxTreeItemId& WXUNUSED(item), { wxFAIL_MSG("not implemented"); - return NULL; + return (wxTextCtrl*)NULL; } wxTextCtrl *wxTreeCtrl::GetEditControl() const { - wxFAIL_MSG("not implemented"); + wxFAIL_MSG("not implemented"); - return NULL; + return (wxTextCtrl*)NULL; } void wxTreeCtrl::EndEditLabel(const wxTreeItemId& WXUNUSED(item), bool WXUNUSED(discardChanges)) { - wxFAIL_MSG("not implemented"); + wxFAIL_MSG("not implemented"); +} + +wxTreeItemCmpFunc tree_ctrl_compare_func_2; + +int tree_ctrl_compare_func_1( wxGenericTreeItem **line1, wxGenericTreeItem **line2 ) +{ + if (tree_ctrl_compare_func_2 == NULL) + { + return strcmp( (*line1)->GetText(), (*line2)->GetText() ); + } + else + { + wxTreeItemData *data1 = (*line1)->GetData(); + wxTreeItemData *data2 = (*line2)->GetData(); + return tree_ctrl_compare_func_2( data1, data2 ); + } } -void wxTreeCtrl::SortChildren( const wxTreeItemId& WXUNUSED(item), - wxTreeItemCmpFunc *WXUNUSED(cmpFunction)) +void wxTreeCtrl::SortChildren( const wxTreeItemId& item, + wxTreeItemCmpFunc *cmpFunction) { - wxFAIL_MSG("not implemented"); + wxGenericTreeItem *gitem = item.m_pItem; + + if (!gitem) return; + + if (cmpFunction == NULL) + tree_ctrl_compare_func_2 = NULL; + else + tree_ctrl_compare_func_2 = *cmpFunction; + + gitem->GetChildren().Sort( *tree_ctrl_compare_func_1 ); + + m_dirty = TRUE; } wxImageList *wxTreeCtrl::GetImageList() const @@ -963,22 +991,23 @@ void wxTreeCtrl::SetStateImageList(wxImageList *imageList) // ----------------------------------------------------------------------------- // helpers // ----------------------------------------------------------------------------- + void wxTreeCtrl::AdjustMyScrollbars() { - if (m_anchor) - { - int x = 0; - int y = 0; - m_anchor->GetSize( x, y ); - y += 2*m_lineHeight; - int x_pos = GetScrollPos( wxHORIZONTAL ); - int y_pos = GetScrollPos( wxVERTICAL ); - SetScrollbars( 10, 10, x/10, y/10, x_pos, y_pos ); - } - else - { - SetScrollbars( 0, 0, 0, 0 ); - } + if (m_anchor) + { + int x = 0; + int y = 0; + m_anchor->GetSize( x, y ); + y += 2*m_lineHeight; + int x_pos = GetScrollPos( wxHORIZONTAL ); + int y_pos = GetScrollPos( wxVERTICAL ); + SetScrollbars( 10, 10, x/10, y/10, x_pos, y_pos ); + } + else + { + SetScrollbars( 0, 0, 0, 0 ); + } } void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) @@ -1012,7 +1041,12 @@ void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) int image_h = 0; int image_w = 0; - if (item->GetImage() != -1) + if ((item->IsExpanded()) && (item->GetSelectedImage() != -1)) + { + m_imageListNormal->GetSize( item->GetSelectedImage(), image_w, image_h ); + image_w += 4; + } + else if (item->GetImage() != -1) { m_imageListNormal->GetSize( item->GetImage(), image_w, image_h ); image_w += 4; @@ -1020,7 +1054,15 @@ void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) dc.DrawRectangle( item->GetX()-2, item->GetY()-2, image_w+text_w+4, text_h+4 ); - if (item->GetImage() != -1) + if ((item->IsExpanded()) && (item->GetSelectedImage() != -1)) + { + dc.SetClippingRegion( item->GetX(), item->GetY(), image_w-2, text_h ); + m_imageListNormal->Draw( item->GetSelectedImage(), dc, + item->GetX(), item->GetY()-1, + wxIMAGELIST_DRAW_TRANSPARENT ); + dc.DestroyClippingRegion(); + } + else if (item->GetImage() != -1) { dc.SetClippingRegion( item->GetX(), item->GetY(), image_w-2, text_h ); m_imageListNormal->Draw( item->GetImage(), dc, @@ -1131,33 +1173,33 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int & void wxTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) ) { - if ( !m_anchor ) - return; + if ( !m_anchor ) + return; - wxPaintDC dc(this); - PrepareDC( dc ); + wxPaintDC dc(this); + PrepareDC( dc ); - dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) ); + dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) ); - dc.SetPen( m_dottedPen ); - m_lineHeight = (int)(dc.GetCharHeight() + 4); + dc.SetPen( m_dottedPen ); + m_lineHeight = (int)(dc.GetCharHeight() + 4); - int y = m_lineHeight / 2 + 2; - PaintLevel( m_anchor, dc, 0, y ); + int y = m_lineHeight / 2 + 2; + PaintLevel( m_anchor, dc, 0, y ); } void wxTreeCtrl::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) { - m_hasFocus = TRUE; - if ( m_current ) - RefreshLine( m_current ); + m_hasFocus = TRUE; + if ( m_current ) + RefreshLine( m_current ); } void wxTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) { - m_hasFocus = FALSE; - if ( m_current ) - RefreshLine( m_current ); + m_hasFocus = FALSE; + if ( m_current ) + RefreshLine( m_current ); } void wxTreeCtrl::OnChar( wxKeyEvent &event ) diff --git a/src/gtk.inc b/src/gtk.inc index 9556d2425f..31dca2714f 100644 --- a/src/gtk.inc +++ b/src/gtk.inc @@ -89,7 +89,6 @@ LIB_CPP_SRC=\ gtk/dcscreen.cpp \ gtk/dnd.cpp \ gtk/dialog.cpp \ - gtk/dirdlg.cpp \ gtk/filedlg.cpp \ gtk/font.cpp \ gtk/frame.cpp \ @@ -122,6 +121,7 @@ LIB_CPP_SRC=\ \ generic/choicdgg.cpp \ generic/colrdlgg.cpp \ + generic/dirdlgg.cpp \ generic/fontdlgg.cpp \ generic/gridg.cpp \ generic/imaglist.cpp \ diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index bc2156d094..efab7e9d5c 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -108,6 +108,9 @@ void wxRadioButton::SetValue( bool val ) { wxCHECK_RET( m_widget != NULL, "invalid radiobutton" ); + if ( val == GetValue() ) + return; + m_blockFirstEvent = TRUE; if (val) diff --git a/src/gtk1/radiobut.cpp b/src/gtk1/radiobut.cpp index bc2156d094..efab7e9d5c 100644 --- a/src/gtk1/radiobut.cpp +++ b/src/gtk1/radiobut.cpp @@ -108,6 +108,9 @@ void wxRadioButton::SetValue( bool val ) { wxCHECK_RET( m_widget != NULL, "invalid radiobutton" ); + if ( val == GetValue() ) + return; + m_blockFirstEvent = TRUE; if (val) -- 2.45.2