X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/223d09f6b523aac674ef9b72a883dfa8d37c5d4e..7b9da2077d0975db6c965a85c91d5aca671ab5e3:/src/generic/treectrl.cpp diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index 57b181dd44..bd47f172a7 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -196,7 +196,13 @@ END_EVENT_TABLE() wxTreeTextCtrl::wxTreeTextCtrl( wxWindow *parent, const wxWindowID id, bool *accept, wxString *res, wxTreeCtrl *owner, const wxString &value, const wxPoint &pos, const wxSize &size, +#if wxUSE_VALIDATORS +# if defined(__VISAGECPP__) + int style, const wxValidator* validator, const wxString &name ) : +# else int style, const wxValidator& validator, const wxString &name ) : +# endif +#endif wxTextCtrl( parent, id, value, pos, size, style, validator, name ) { m_res = res; @@ -517,12 +523,25 @@ void wxTreeCtrl::Init() m_dragCount = 0; m_renameTimer = new wxTreeRenameTimer( this ); + + m_normalFont = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ); + m_boldFont = wxFont( m_normalFont.GetPointSize(), + m_normalFont.GetFamily(), + m_normalFont.GetStyle(), + wxBOLD, + m_normalFont.GetUnderlined()); } bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, +#if wxUSE_VALIDATORS +# if defined(__VISAGECPP__) + const wxValidator *validator, +# else const wxValidator &validator, +# endif +#endif const wxString& name ) { Init(); @@ -816,49 +835,53 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parentId, int image, int selImage, wxTreeItemData *data) { - wxGenericTreeItem *parent = parentId.m_pItem; - if ( !parent ) - { - // should we give a warning here? - return AddRoot(text, image, selImage, data); - } + wxGenericTreeItem *parent = parentId.m_pItem; + if ( !parent ) + { + // should we give a warning here? + return AddRoot(text, image, selImage, data); + } - wxClientDC dc(this); - wxGenericTreeItem *item = new wxGenericTreeItem(parent, - text, dc, - image, selImage, - data); + wxClientDC dc(this); + wxGenericTreeItem *item = + new wxGenericTreeItem( parent, text, dc, image, selImage, data ); - if ( data != NULL ) - { - data->m_pItem = item; - } + if ( data != NULL ) + { + data->m_pItem = item; + } - parent->Insert( item, previous ); + parent->Insert( item, previous ); - m_dirty = TRUE; + m_dirty = TRUE; - return item; + return item; } wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text, int image, int selImage, wxTreeItemData *data) { - wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") ); + wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") ); - wxClientDC dc(this); - m_anchor = new wxGenericTreeItem((wxGenericTreeItem *)NULL, text, dc, + wxClientDC dc(this); + m_anchor = new wxGenericTreeItem((wxGenericTreeItem *)NULL, text, dc, image, selImage, data); - if ( data != NULL ) - { - data->m_pItem = m_anchor; - } + if ( data != NULL ) + { + data->m_pItem = m_anchor; + } + + if (!HasFlag(wxTR_MULTIPLE)) + { + m_current = m_key_current = m_anchor; + m_current->SetHilight( TRUE ); + } - Refresh(); - AdjustMyScrollbars(); + Refresh(); + AdjustMyScrollbars(); - return m_anchor; + return m_anchor; } wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent, @@ -963,7 +986,9 @@ void wxTreeCtrl::Expand(const wxTreeItemId& itemId) wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId() ); event.m_item = item; event.SetEventObject( this ); - if ( ProcessEvent( event ) && event.m_code ) + +// if ( ProcessEvent( event ) && event.m_code ) TODO: Was this a typo ? + if ( ProcessEvent( event ) && !event.IsAllowed() ) { // cancelled by program return; @@ -1283,7 +1308,7 @@ void wxTreeCtrl::ScrollTo(const wxTreeItemId &item) // FIXME: tree sorting functions are not reentrant and not MT-safe! static wxTreeCtrl *s_treeBeingSorted = NULL; -static int tree_ctrl_compare_func(wxGenericTreeItem **item1, +static int LINKAGEMODE tree_ctrl_compare_func(wxGenericTreeItem **item1, wxGenericTreeItem **item2) { wxCHECK_MSG( s_treeBeingSorted, 0, wxT("bug in wxTreeCtrl::SortChildren()") ); @@ -1392,28 +1417,8 @@ int wxTreeCtrl::GetLineHeight(wxGenericTreeItem *item) const void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) { - // render bold items in bold - wxFont fontOld; - wxFont fontNew; - if (item->IsBold()) - { - fontOld = dc.GetFont(); - if (fontOld.Ok()) - { - // VZ: is there any better way to make a bold variant of old font? - fontNew = wxFont( fontOld.GetPointSize(), - fontOld.GetFamily(), - fontOld.GetStyle(), - wxBOLD, - fontOld.GetUnderlined()); - dc.SetFont(fontNew); - } - else - { - wxFAIL_MSG(wxT("wxDC::GetFont() failed!")); - } - } + dc.SetFont(m_boldFont); long text_w = 0; long text_h = 0; @@ -1446,11 +1451,8 @@ void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) dc.DrawText( item->GetText(), image_w + item->GetX(), item->GetY() + ((total_h > text_h) ? (total_h - text_h)/2 : 0)); - // restore normal font for bold items - if (fontOld.Ok()) - { - dc.SetFont( fontOld); - } + // restore normal font + dc.SetFont( m_normalFont ); } // Now y stands for the top of the item, whereas it used to stand for middle ! @@ -1598,9 +1600,10 @@ void wxTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxPaintDC dc(this); PrepareDC( dc ); - dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) ); - + dc.SetFont( m_normalFont ); dc.SetPen( m_dottedPen ); + + // this is now done dynamically //if(GetImageList() == NULL) // m_lineHeight = (int)(dc.GetCharHeight() + 4); @@ -1899,7 +1902,7 @@ void wxTreeCtrl::OnRenameAccept() void wxTreeCtrl::OnMouse( wxMouseEvent &event ) { - if ( !(event.LeftUp() || event.LeftDClick() || event.Dragging()) ) return; + if ( !(event.LeftUp() || event.RightDown() || event.LeftDClick() || event.Dragging()) ) return; if ( !m_anchor ) return; @@ -1937,6 +1940,15 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event ) if (item == NULL) return; /* we hit the blank area */ + if (event.RightDown()) { + wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,GetId()); + nevent.m_item=item; + nevent.m_code=0; + nevent.SetEventObject(this); + GetEventHandler()->ProcessEvent(nevent); + return; + } + if (event.LeftUp() && (item == m_current) && (flags & wxTREE_HITTEST_ONITEMLABEL) && HasFlag(wxTR_EDIT_LABELS) ) @@ -1988,33 +2000,14 @@ void wxTreeCtrl::CalculateSize( wxGenericTreeItem *item, wxDC &dc ) long text_w = 0; long text_h = 0; - wxFont fontOld; - wxFont fontNew; if (item->IsBold()) - { - fontOld = dc.GetFont(); - if (fontOld.Ok()) - { - // VZ: is there any better way to make a bold variant of old font? - fontNew = wxFont( fontOld.GetPointSize(), - fontOld.GetFamily(), - fontOld.GetStyle(), - wxBOLD, - fontOld.GetUnderlined()); - dc.SetFont(fontNew); - } - else - { - wxFAIL_MSG(wxT("wxDC::GetFont() failed!")); - } - } + dc.SetFont(m_boldFont); dc.GetTextExtent( item->GetText(), &text_w, &text_h ); text_h+=2; - // restore normal font for bold items - if (fontOld.Ok()) - dc.SetFont( fontOld); + // restore normal font + dc.SetFont( m_normalFont ); int image_h = 0; int image_w = 0; @@ -2069,7 +2062,7 @@ void wxTreeCtrl::CalculatePositions() wxClientDC dc(this); PrepareDC( dc ); - dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) ); + dc.SetFont( m_normalFont ); dc.SetPen( m_dottedPen ); //if(GetImageList() == NULL)