made wxTreeCtrl::GetNextVisible() behave in the same way in Win32 as in the generic version and implemented GetPrevVisible() in the generic version

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49085 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-10-07 21:58:51 +00:00
parent f0eebb39bc
commit f73eddd2a5
6 changed files with 149 additions and 26 deletions

View File

@@ -195,6 +195,8 @@ All (GUI):
- Added wxSYS_DCLICK_TIME system metric constant (Arne Steinarson) - Added wxSYS_DCLICK_TIME system metric constant (Arne Steinarson)
- Added wxApp::Get/SetAppDisplayName() (Brian A. Vanderburg II) - Added wxApp::Get/SetAppDisplayName() (Brian A. Vanderburg II)
- Added wxWindow::GetPopupMenuSelectionFromUser() (Arne Steinarson) - Added wxWindow::GetPopupMenuSelectionFromUser() (Arne Steinarson)
- Implemented wxTreeCtrl::GetPrevVisible() in the generic version and made the
behaviour of GetNextSibling() consistent between wxMSW and generic versions
wxGTK: wxGTK:

View File

@@ -332,7 +332,7 @@ will be sent which can be vetoed as well.
\func{void}{EndEditLabel}{\param{bool }{cancelEdit}} \func{void}{EndEditLabel}{\param{bool }{cancelEdit}}
Ends label editing. If {\it cancelEdit} is {\tt true}, the edit will be cancelled. Ends label editing. If {\it cancelEdit} is \true, the edit will be cancelled.
This function is currently supported under Windows only. This function is currently supported under Windows only.
@@ -371,13 +371,13 @@ Expands the given item and all its children recursively.
\membersection{wxTreeCtrl::GetBoundingRect}\label{wxtreectrlgetitemrect} \membersection{wxTreeCtrl::GetBoundingRect}\label{wxtreectrlgetitemrect}
\constfunc{bool}{GetBoundingRect}{\param{const wxTreeItemId\&}{ item}, \param{wxRect\& }{rect}, \param{bool }{textOnly = {\tt false}}} \constfunc{bool}{GetBoundingRect}{\param{const wxTreeItemId\&}{ item}, \param{wxRect\& }{rect}, \param{bool }{textOnly = \false}}
Retrieves the rectangle bounding the {\it item}. If {\it textOnly} is {\tt true}, Retrieves the rectangle bounding the {\it item}. If {\it textOnly} is \true,
only the rectangle around the item's label will be returned, otherwise the only the rectangle around the item's label will be returned, otherwise the
item's image is also taken into account. item's image is also taken into account.
The return value is {\tt true} if the rectangle was successfully retrieved or {\tt false} The return value is \true if the rectangle was successfully retrieved or \false
if it was not (in this case {\it rect} is not changed) -- for example, if the if it was not (in this case {\it rect} is not changed) -- for example, if the
item is currently invisible. item is currently invisible.
@@ -404,9 +404,9 @@ This function is only available in the generic version.
\membersection{wxTreeCtrl::GetChildrenCount}\label{wxtreectrlgetchildrencount} \membersection{wxTreeCtrl::GetChildrenCount}\label{wxtreectrlgetchildrencount}
\constfunc{unsigned int}{GetChildrenCount}{\param{const wxTreeItemId\&}{ item}, \param{bool}{ recursively = {\tt true}}} \constfunc{unsigned int}{GetChildrenCount}{\param{const wxTreeItemId\&}{ item}, \param{bool}{ recursively = \true}}
Returns the number of items in the branch. If {\it recursively} is {\tt true}, returns the total number Returns the number of items in the branch. If {\it recursively} is \true, returns the total number
of descendants, otherwise only one level of children is counted. of descendants, otherwise only one level of children is counted.
@@ -439,7 +439,7 @@ to make these functions reentrant (i.e. allow more than one
enumeration on one and the same object simultaneously). The cookie passed to enumeration on one and the same object simultaneously). The cookie passed to
GetFirstChild and GetNextChild should be the same variable. GetFirstChild and GetNextChild should be the same variable.
Returns an invalid tree item (i.e. IsOk() returns {\tt false}) if there are no further children. Returns an invalid tree item (i.e. IsOk() returns \false) if there are no further children.
\wxheading{See also} \wxheading{See also}
@@ -603,7 +603,10 @@ Returns an invalid tree item if there are no further siblings.
\constfunc{wxTreeItemId}{GetNextVisible}{\param{const wxTreeItemId\&}{ item}} \constfunc{wxTreeItemId}{GetNextVisible}{\param{const wxTreeItemId\&}{ item}}
Returns the next visible item. Returns the next visible item or an invalid item if this item is the last
visible one.
Notice that the \arg{item} itself must be visible.
\membersection{wxTreeCtrl::GetItemParent}\label{wxtreectrlgetitemparent} \membersection{wxTreeCtrl::GetItemParent}\label{wxtreectrlgetitemparent}
@@ -630,7 +633,10 @@ Returns an invalid tree item if there are no further children.
\constfunc{wxTreeItemId}{GetPrevVisible}{\param{const wxTreeItemId\&}{ item}} \constfunc{wxTreeItemId}{GetPrevVisible}{\param{const wxTreeItemId\&}{ item}}
Returns the previous visible item. Returns the previous visible item or an invalid item if this item is the first
visible one.
Notice that the \arg{item} itself must be visible.
\membersection{wxTreeCtrl::GetQuickBestSize}\label{wxtreectrlgetquickbestsize} \membersection{wxTreeCtrl::GetQuickBestSize}\label{wxtreectrlgetquickbestsize}
@@ -657,7 +663,7 @@ Returns the root item for the tree control.
\constfunc{int}{GetItemSelectedImage}{\param{const wxTreeItemId\& }{item}} \constfunc{int}{GetItemSelectedImage}{\param{const wxTreeItemId\& }{item}}
Gets the selected item image (this function is obsolete, use Gets the selected item image (this function is obsolete, use
{\tt GetItemImage(item, wxTreeItemIcon\_Selected}) instead). {\tt GetItemImage(item, wxTreeItemIcon\_Selected)} instead).
\membersection{wxTreeCtrl::GetSelection}\label{wxtreectrlgetselection} \membersection{wxTreeCtrl::GetSelection}\label{wxtreectrlgetselection}
@@ -747,7 +753,7 @@ both selected and unselected items.
\constfunc{bool}{IsBold}{\param{const wxTreeItemId\& }{item}} \constfunc{bool}{IsBold}{\param{const wxTreeItemId\& }{item}}
Returns {\tt true} if the given item is in bold state. Returns \true if the given item is in bold state.
See also: \helpref{SetItemBold}{wxtreectrlsetitembold} See also: \helpref{SetItemBold}{wxtreectrlsetitembold}
@@ -763,28 +769,28 @@ Returns \true if the control is empty (i.e. has no items, even no root one).
\constfunc{bool}{IsExpanded}{\param{const wxTreeItemId\&}{ item}} \constfunc{bool}{IsExpanded}{\param{const wxTreeItemId\&}{ item}}
Returns {\tt true} if the item is expanded (only makes sense if it has children). Returns \true if the item is expanded (only makes sense if it has children).
\membersection{wxTreeCtrl::IsSelected}\label{wxtreectrlisselected} \membersection{wxTreeCtrl::IsSelected}\label{wxtreectrlisselected}
\constfunc{bool}{IsSelected}{\param{const wxTreeItemId\&}{ item}} \constfunc{bool}{IsSelected}{\param{const wxTreeItemId\&}{ item}}
Returns {\tt true} if the item is selected. Returns \true if the item is selected.
\membersection{wxTreeCtrl::IsVisible}\label{wxtreectrlisvisible} \membersection{wxTreeCtrl::IsVisible}\label{wxtreectrlisvisible}
\constfunc{bool}{IsVisible}{\param{const wxTreeItemId\&}{ item}} \constfunc{bool}{IsVisible}{\param{const wxTreeItemId\&}{ item}}
Returns {\tt true} if the item is visible (it might be outside the view, or not expanded). Returns \true if the item is visible on the screen.
\membersection{wxTreeCtrl::ItemHasChildren}\label{wxtreectrlitemhaschildren} \membersection{wxTreeCtrl::ItemHasChildren}\label{wxtreectrlitemhaschildren}
\constfunc{bool}{ItemHasChildren}{\param{const wxTreeItemId\&}{ item}} \constfunc{bool}{ItemHasChildren}{\param{const wxTreeItemId\&}{ item}}
Returns {\tt true} if the item has children. Returns \true if the item has children.
\membersection{wxTreeCtrl::OnCompareItems}\label{wxtreectrloncompareitems} \membersection{wxTreeCtrl::OnCompareItems}\label{wxtreectrloncompareitems}
@@ -879,9 +885,9 @@ Sets the colour of the item's background.
\membersection{wxTreeCtrl::SetItemBold}\label{wxtreectrlsetitembold} \membersection{wxTreeCtrl::SetItemBold}\label{wxtreectrlsetitembold}
\func{void}{SetItemBold}{\param{const wxTreeItemId\& }{item}, \param{bool}{ bold = {\tt true}}} \func{void}{SetItemBold}{\param{const wxTreeItemId\& }{item}, \param{bool}{ bold = \true}}
Makes item appear in bold font if {\it bold} parameter is {\tt true} or resets it to Makes item appear in bold font if {\it bold} parameter is \true or resets it to
the normal state. the normal state.
See also: \helpref{IsBold}{wxtreectrlisbold} See also: \helpref{IsBold}{wxtreectrlisbold}
@@ -911,7 +917,7 @@ tree->GetItemData(item)->SetData(data).}
\membersection{wxTreeCtrl::SetItemDropHighlight}\label{wxtreectrlsetitemdrophighlight} \membersection{wxTreeCtrl::SetItemDropHighlight}\label{wxtreectrlsetitemdrophighlight}
\func{void}{SetItemDropHighlight}{\param{const wxTreeItemId\&}{ item}, \param{bool}{highlight = {\tt true}}} \func{void}{SetItemDropHighlight}{\param{const wxTreeItemId\&}{ item}, \param{bool}{highlight = \true}}
Gives the item the visual feedback for Drag'n'Drop actions, which is Gives the item the visual feedback for Drag'n'Drop actions, which is
useful if something is dragged from the outside onto the tree control useful if something is dragged from the outside onto the tree control
@@ -933,7 +939,7 @@ although font attributes may vary.
\membersection{wxTreeCtrl::SetItemHasChildren}\label{wxtreectrlsetitemhaschildren} \membersection{wxTreeCtrl::SetItemHasChildren}\label{wxtreectrlsetitemhaschildren}
\func{void}{SetItemHasChildren}{\param{const wxTreeItemId\&}{ item}, \param{bool }{hasChildren = {\tt true}}} \func{void}{SetItemHasChildren}{\param{const wxTreeItemId\&}{ item}, \param{bool }{hasChildren = \true}}
Force appearance of the button next to the item. This is useful to Force appearance of the button next to the item. This is useful to
allow the user to expand the items which don't have any children now, allow the user to expand the items which don't have any children now,
@@ -954,7 +960,8 @@ for the description of the {\it which} parameter.
\func{void}{SetItemSelectedImage}{\param{const wxTreeItemId\&}{ item}, \param{int }{selImage}} \func{void}{SetItemSelectedImage}{\param{const wxTreeItemId\&}{ item}, \param{int }{selImage}}
Sets the selected item image (this function is obsolete, use {\tt SetItemImage(item, wxTreeItemIcon\_Selected}) instead). Sets the selected item image (this function is obsolete, use
{\tt SetItemImage(item, wxTreeItemIcon\_Selected)} instead).
\membersection{wxTreeCtrl::SetItemText}\label{wxtreectrlsetitemtext} \membersection{wxTreeCtrl::SetItemText}\label{wxtreectrlsetitemtext}

View File

@@ -111,6 +111,13 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
MENU_LINK(DecSpacing) MENU_LINK(DecSpacing)
MENU_LINK(ToggleIcon) MENU_LINK(ToggleIcon)
MENU_LINK(SelectRoot) MENU_LINK(SelectRoot)
MENU_LINK(ShowFirstVisible)
#ifdef wxHAS_LAST_VISIBLE
MENU_LINK(ShowLastVisible)
#endif // wxHAS_LAST_VISIBLE
MENU_LINK(ShowNextVisible)
MENU_LINK(ShowPrevVisible)
#undef MENU_LINK #undef MENU_LINK
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -140,7 +147,7 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown) EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, MyTreeCtrl::OnItemActivated) EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, MyTreeCtrl::OnItemActivated)
// so many differents ways to handle right mouse button clicks... // so many different ways to handle right mouse button clicks...
EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu) EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu)
// EVT_TREE_ITEM_MENU is the preferred event for creating context menus // EVT_TREE_ITEM_MENU is the preferred event for creating context menus
// on a tree control, because it includes the point of the click or item, // on a tree control, because it includes the point of the click or item,
@@ -254,6 +261,13 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
item_menu->Append(TreeTest_ClearBold, wxT("Make item &not bold")); item_menu->Append(TreeTest_ClearBold, wxT("Make item &not bold"));
item_menu->AppendSeparator(); item_menu->AppendSeparator();
item_menu->Append(TreeTest_ToggleIcon, wxT("Toggle the item's &icon")); item_menu->Append(TreeTest_ToggleIcon, wxT("Toggle the item's &icon"));
item_menu->AppendSeparator();
item_menu->Append(TreeTest_ShowFirstVisible, wxT("Show &first visible"));
#ifdef wxHAS_LAST_VISIBLE
item_menu->Append(TreeTest_ShowLastVisible, wxT("Show &last visible"));
#endif // wxHAS_LAST_VISIBLE
item_menu->Append(TreeTest_ShowNextVisible, wxT("Show &next visible"));
item_menu->Append(TreeTest_ShowPrevVisible, wxT("Show &previous visible"));
#ifndef NO_MULTIPLE_SELECTION #ifndef NO_MULTIPLE_SELECTION
item_menu->AppendSeparator(); item_menu->AppendSeparator();
@@ -701,6 +715,38 @@ void MyFrame::OnToggleIcon(wxCommandEvent& WXUNUSED(event))
m_treeCtrl->DoToggleIcon(item); m_treeCtrl->DoToggleIcon(item);
} }
void MyFrame::DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label)
{
const wxTreeItemId item = (m_treeCtrl->*pfn)();
if ( !item.IsOk() )
wxLogMessage("There is no %s item", label);
else
wxLogMessage("The %s item is \"%s\"",
label, m_treeCtrl->GetItemText(item));
}
void MyFrame::DoShowNextOrPrev(TreeFunc1_t pfn, const wxString& label)
{
wxTreeItemId item = m_treeCtrl->GetSelection();
CHECK_ITEM( item );
if ( !m_treeCtrl->IsVisible(item) )
{
wxLogMessage("The selected item must be visible.");
return;
}
item = (m_treeCtrl->*pfn)(item);
if ( !item.IsOk() )
wxLogMessage("There is no %s item", label);
else
wxLogMessage("The %s item is \"%s\"",
label, m_treeCtrl->GetItemText(item));
}
void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
{ {
wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetForegroundColour()); wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetForegroundColour());

View File

@@ -225,6 +225,18 @@ public:
void OnToggleIcon(wxCommandEvent& event); void OnToggleIcon(wxCommandEvent& event);
void OnShowFirstVisible(wxCommandEvent& WXUNUSED(event))
{ DoShowFirstOrLast(&wxTreeCtrl::GetFirstVisibleItem, "first visible"); }
#ifdef wxHAS_LAST_VISIBLE // we don't have it currently but may add later
void OnShowLastVisible(wxCommandEvent& WXUNUSED(event))
{ DoShowFirstOrLast(&wxTreeCtrl::GetLastVisibleItem, "last visible"); }
#endif // wxHAS_LAST_VISIBLE
void OnShowNextVisible(wxCommandEvent& WXUNUSED(event))
{ DoShowNextOrPrev(&wxTreeCtrl::GetNextVisible, "next visible"); }
void OnShowPrevVisible(wxCommandEvent& WXUNUSED(event))
{ DoShowNextOrPrev(&wxTreeCtrl::GetPrevVisible, "previous visible"); }
void OnIdle(wxIdleEvent& event); void OnIdle(wxIdleEvent& event);
void OnSize(wxSizeEvent& event); void OnSize(wxSizeEvent& event);
@@ -238,6 +250,14 @@ private:
void CreateTreeWithDefStyle(); void CreateTreeWithDefStyle();
void CreateTree(long style); void CreateTree(long style);
// common parts of OnShowFirst/LastVisible() and OnShowNext/PrevVisible()
typedef wxTreeItemId (wxTreeCtrl::*TreeFunc0_t)() const;
void DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label);
typedef wxTreeItemId (wxTreeCtrl::*TreeFunc1_t)(const wxTreeItemId&) const;
void DoShowNextOrPrev(TreeFunc1_t pfn, const wxString& label);
wxPanel *m_panel; wxPanel *m_panel;
MyTreeCtrl *m_treeCtrl; MyTreeCtrl *m_treeCtrl;
#if wxUSE_LOG #if wxUSE_LOG
@@ -297,5 +317,9 @@ enum
TreeTest_Select, TreeTest_Select,
TreeTest_Unselect, TreeTest_Unselect,
TreeTest_SelectRoot, TreeTest_SelectRoot,
TreeTest_ShowFirstVisible,
TreeTest_ShowLastVisible,
TreeTest_ShowNextVisible,
TreeTest_ShowPrevVisible,
TreeTest_Ctrl = 1000 TreeTest_Ctrl = 1000
}; };

View File

@@ -1315,6 +1315,7 @@ wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const
wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
{ {
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
wxASSERT_MSG( IsVisible(item), wxT("this item itself should be visible") );
wxTreeItemId id = item; wxTreeItemId id = item;
if (id.IsOk()) if (id.IsOk())
@@ -1331,10 +1332,37 @@ wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const
{ {
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
wxASSERT_MSG( IsVisible(item), wxT("this item itself should be visible") );
wxFAIL_MSG(wxT("not implemented")); // find out the starting point
wxTreeItemId prevItem = GetPrevSibling(item);
if ( !prevItem.IsOk() )
{
prevItem = GetItemParent(item);
}
// find the first visible item after it
while ( prevItem.IsOk() && !IsVisible(prevItem) )
{
prevItem = GetNext(prevItem);
if ( !prevItem.IsOk() || prevItem == item )
{
// there are no visible items before item
return wxTreeItemId(); return wxTreeItemId();
}
}
// from there we must be able to navigate until this item
while ( prevItem.IsOk() )
{
const wxTreeItemId nextItem = GetNextVisible(prevItem);
if ( !nextItem.IsOk() || nextItem == item )
break;
prevItem = nextItem;
}
return prevItem;
} }
// called by wxTextTreeCtrl when it marks itself for deletion // called by wxTextTreeCtrl when it marks itself for deletion

View File

@@ -1354,7 +1354,15 @@ wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
wxASSERT_MSG( IsVisible(item), wxT("The item you call GetNextVisible() for must be visible itself!")); wxASSERT_MSG( IsVisible(item), wxT("The item you call GetNextVisible() for must be visible itself!"));
return wxTreeItemId(TreeView_GetNextVisible(GetHwnd(), HITEM(item))); wxTreeItemId next(TreeView_GetNextVisible(GetHwnd(), HITEM(item)));
if ( next.IsOk() && !IsVisible(next) )
{
// Win32 considers that any non-collapsed item is visible while we want
// to return only really visible items
next.Unset();
}
return next;
} }
wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const
@@ -1362,7 +1370,15 @@ wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
wxASSERT_MSG( IsVisible(item), wxT("The item you call GetPrevVisible() for must be visible itself!")); wxASSERT_MSG( IsVisible(item), wxT("The item you call GetPrevVisible() for must be visible itself!"));
return wxTreeItemId(TreeView_GetPrevVisible(GetHwnd(), HITEM(item))); wxTreeItemId prev(TreeView_GetPrevVisible(GetHwnd(), HITEM(item)));
if ( prev.IsOk() && !IsVisible(prev) )
{
// just as above, Win32 function will happily return the previous item
// in the tree for the first visible item too
prev.Unset();
}
return prev;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------