1. changed spelling error in wxTR_HAS_VARIABLE_HEIGHT (missing 'E')
2. compile fix for dcscreen.cpp 3. editing labels in place works in the tree ctrl and shown in the sample 4. sped up items deletion in the listview git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3110 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -768,7 +768,7 @@ enum
|
||||
#define wxTR_SINGLE 0x0000
|
||||
#define wxTR_MULTIPLE 0x0020
|
||||
#define wxTR_EXTENDED 0x0040
|
||||
#define wxTR_HAS_VARIABLE_ROW_HIGHT 0x0080
|
||||
#define wxTR_HAS_VARIABLE_ROW_HEIGHT 0x0080
|
||||
|
||||
/*
|
||||
* wxListCtrl flags
|
||||
|
@@ -30,7 +30,7 @@ public:
|
||||
/*
|
||||
* Public interface
|
||||
*/
|
||||
wxSpinButton();
|
||||
wxSpinButton() { }
|
||||
|
||||
wxSpinButton(wxWindow *parent,
|
||||
wxWindowID id = -1,
|
||||
|
@@ -504,12 +504,16 @@ public:
|
||||
// keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only)
|
||||
int GetCode() const { return m_code; }
|
||||
|
||||
// label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
|
||||
const wxString& GetLabel() const { return m_label; }
|
||||
|
||||
private:
|
||||
// @@ we could save some space by using union here
|
||||
// TODO we could save some space by using union here
|
||||
int m_code;
|
||||
wxTreeItemId m_item,
|
||||
m_itemOld;
|
||||
wxPoint m_pointDrag;
|
||||
wxString m_label;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxTreeEvent)
|
||||
};
|
||||
@@ -524,7 +528,11 @@ typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
|
||||
#define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
|
||||
#define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
|
||||
|
||||
// GetItem() returns the itme whose label is being edited
|
||||
// GetItem() returns the itme whose label is being edited, GetLabel() returns
|
||||
// the current item label for BEGIN and the would be new one for END.
|
||||
//
|
||||
// Vetoing BEGIN event means that label editing won't happen at all,
|
||||
// vetoing END means that the new value is discarded and the old one kept
|
||||
#define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
|
||||
#define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
|
||||
|
||||
|
@@ -45,6 +45,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
|
||||
EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
|
||||
EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
|
||||
EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
|
||||
@@ -131,6 +132,9 @@ bool MyApp::OnInit(void)
|
||||
file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text");
|
||||
file_menu->Append(LIST_DESELECT_ALL, "&Deselect All");
|
||||
file_menu->Append(LIST_SELECT_ALL, "S&elect All");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(LIST_DELETE_ALL, "Delete &all items");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(BUSY_ON, "&Busy cursor on");
|
||||
file_menu->Append(BUSY_OFF, "&Busy cursor off");
|
||||
file_menu->AppendSeparator();
|
||||
@@ -260,7 +264,7 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
|
||||
m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
|
||||
m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
|
||||
|
||||
for ( int i=0; i < 30; i++)
|
||||
for ( int i = 0; i < 3000; i++ )
|
||||
{
|
||||
wxChar buf[50];
|
||||
wxSprintf(buf, _T("This is item %d"), i);
|
||||
@@ -336,6 +340,17 @@ void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
(void)wxGetElapsedTime(TRUE);
|
||||
|
||||
int nItems = m_listCtrl->GetItemCount();
|
||||
m_listCtrl->DeleteAllItems();
|
||||
|
||||
wxLogMessage("Deleting %d items took %ld ms",
|
||||
nItems, wxGetElapsedTime());
|
||||
}
|
||||
|
||||
// MyListCtrl
|
||||
|
||||
void MyListCtrl::OnBeginDrag(wxListEvent& WXUNUSED(event))
|
||||
|
@@ -12,7 +12,7 @@
|
||||
// Define a new application type
|
||||
class MyApp: public wxApp
|
||||
{ public:
|
||||
bool OnInit(void);
|
||||
bool OnInit();
|
||||
|
||||
wxImageList *m_imageListNormal;
|
||||
wxImageList *m_imageListSmall;
|
||||
@@ -46,12 +46,13 @@ public:
|
||||
|
||||
// Define a new frame type
|
||||
class MyFrame: public wxFrame
|
||||
{ public:
|
||||
{
|
||||
public:
|
||||
MyListCtrl *m_listCtrl;
|
||||
wxTextCtrl *m_logWindow;
|
||||
|
||||
MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
|
||||
~MyFrame(void);
|
||||
~MyFrame();
|
||||
|
||||
public:
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
@@ -64,8 +65,11 @@ class MyFrame: public wxFrame
|
||||
void OnSmallIconTextView(wxCommandEvent& event);
|
||||
void OnDeselectAll(wxCommandEvent& event);
|
||||
void OnSelectAll(wxCommandEvent& event);
|
||||
void OnDeleteAll(wxCommandEvent& event);
|
||||
|
||||
void BusyOn(wxCommandEvent& event);
|
||||
void BusyOff(wxCommandEvent& event);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
@@ -83,6 +87,7 @@ class MyFrame: public wxFrame
|
||||
#define LIST_ABOUT 102
|
||||
#define BUSY_ON 10
|
||||
#define BUSY_OFF 11
|
||||
#define LIST_DELETE_ALL 12
|
||||
|
||||
#define LIST_CTRL 1000
|
||||
|
||||
|
@@ -35,22 +35,17 @@
|
||||
|
||||
#include "treetest.h"
|
||||
|
||||
#ifdef wxTR_HAS_VARIABLE_ROW_HIGHT
|
||||
#define USE_TR_HAS_VARIABLE_ROW_HIGHT 1
|
||||
#else
|
||||
#define USE_TR_HAS_VARIABLE_ROW_HIGHT 0
|
||||
#ifdef __WXMSW__
|
||||
#define NO_ADVANCED_FEATURES
|
||||
#endif
|
||||
|
||||
// under Windows the icons are in the .rc file
|
||||
#ifndef __WXMSW__
|
||||
#if !USE_TR_HAS_VARIABLE_ROW_HIGHT
|
||||
#include "icon1.xpm"
|
||||
#endif
|
||||
#include "icon2.xpm"
|
||||
#include "mondrian.xpm"
|
||||
#endif
|
||||
|
||||
|
||||
// verify that the item is ok and insult the user if it is not
|
||||
#define CHECK_ITEM( item ) if ( !item.IsOk() ) { \
|
||||
wxMessageBox("Please select some item first!", \
|
||||
@@ -157,9 +152,8 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
|
||||
tree_menu->Append(TreeTest_IncSpacing, "Add 5 points to spacing\tCtrl-I");
|
||||
tree_menu->Append(TreeTest_DecSpacing, "Reduce spacing by 5 points\tCtrl-R");
|
||||
|
||||
item_menu->AppendSeparator();
|
||||
item_menu->Append(TreeTest_Dump, "&Dump item children");
|
||||
#ifdef wxTR_MULTIPLE
|
||||
#ifndef NO_ADVANCED_FEATURES
|
||||
item_menu->Append(TreeTest_Dump_Selected, "Dump selected items\tAlt-S");
|
||||
#endif
|
||||
item_menu->Append(TreeTest_Rename, "&Rename item...");
|
||||
@@ -177,11 +171,10 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
|
||||
m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxTR_HAS_BUTTONS |
|
||||
#ifdef wxTR_MULTIPLE
|
||||
wxTR_EDIT_LABELS |
|
||||
#ifndef NO_ADVANCED_FEATURES
|
||||
wxTR_MULTIPLE |
|
||||
#endif
|
||||
#if USE_TR_HAS_VARIABLE_ROW_HIGHT
|
||||
wxTR_HAS_VARIABLE_ROW_HIGHT |
|
||||
wxTR_HAS_VARIABLE_ROW_HEIGHT |
|
||||
#endif
|
||||
wxSUNKEN_BORDER);
|
||||
wxTextCtrl *textCtrl = new wxTextCtrl(this, -1, "",
|
||||
@@ -231,8 +224,7 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxMessageBox("Tree test sample\n"
|
||||
"Julian Smart (c) 1997,\n"
|
||||
"Vadim Zeitlin (c) 1998",
|
||||
"(c) Julian Smart 1997, Vadim Zeitlin 1998",
|
||||
"About tree test",
|
||||
wxOK | wxICON_INFORMATION, this);
|
||||
}
|
||||
@@ -243,6 +235,8 @@ void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
CHECK_ITEM( item );
|
||||
|
||||
// old code - now we edit in place
|
||||
#if 0
|
||||
static wxString s_text;
|
||||
s_text = wxGetTextFromUser("New name: ", "Tree sample question",
|
||||
s_text, this);
|
||||
@@ -250,6 +244,10 @@ void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_treeCtrl->SetItemText(item, s_text);
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
// TODO demonstrate creating a custom edit control...
|
||||
(void)m_treeCtrl->EditLabel(item);
|
||||
}
|
||||
|
||||
void MyFrame::DoSort(bool reverse)
|
||||
@@ -272,7 +270,7 @@ void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
#ifdef wxTR_MULTIPLE
|
||||
#ifndef NO_ADVANCED_FEATURES
|
||||
wxArrayTreeItemIds array;
|
||||
|
||||
m_treeCtrl->GetSelections(array);
|
||||
@@ -510,8 +508,6 @@ void MyTreeCtrl::name(wxTreeEvent& WXUNUSED(event)) \
|
||||
|
||||
TREE_EVENT_HANDLER(OnBeginDrag)
|
||||
TREE_EVENT_HANDLER(OnBeginRDrag)
|
||||
TREE_EVENT_HANDLER(OnBeginLabelEdit)
|
||||
TREE_EVENT_HANDLER(OnEndLabelEdit)
|
||||
TREE_EVENT_HANDLER(OnDeleteItem)
|
||||
TREE_EVENT_HANDLER(OnGetInfo)
|
||||
TREE_EVENT_HANDLER(OnSetInfo)
|
||||
@@ -523,13 +519,40 @@ TREE_EVENT_HANDLER(OnSelChanging)
|
||||
|
||||
#undef TREE_EVENT_HANDLER
|
||||
|
||||
void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event)
|
||||
{
|
||||
wxLogMessage("OnBeginLabelEdit");
|
||||
|
||||
// for testing, prevent this items label editing
|
||||
wxTreeItemId itemId = event.GetItem();
|
||||
if ( IsTestItem(itemId) )
|
||||
{
|
||||
wxMessageBox("You can't edit this item.");
|
||||
|
||||
event.Veto();
|
||||
}
|
||||
}
|
||||
|
||||
void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event)
|
||||
{
|
||||
wxLogMessage("OnEndLabelEdit");
|
||||
|
||||
// don't allow anything except letters in the labels
|
||||
if ( !event.GetLabel().IsWord() )
|
||||
{
|
||||
wxMessageBox("The label should contain only letters.");
|
||||
|
||||
event.Veto();
|
||||
}
|
||||
}
|
||||
|
||||
void MyTreeCtrl::OnItemCollapsing(wxTreeEvent& event)
|
||||
{
|
||||
wxLogMessage("OnItemCollapsing");
|
||||
|
||||
// for testing, prevent the user from collapsing the first child folder
|
||||
wxTreeItemId itemId = event.GetItem();
|
||||
if ( GetParent(itemId) == GetRootItem() && !GetPrevSibling(itemId) )
|
||||
if ( IsTestItem(itemId) )
|
||||
{
|
||||
wxMessageBox("You can't collapse this item.");
|
||||
|
||||
|
@@ -71,6 +71,13 @@ public:
|
||||
protected:
|
||||
virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
|
||||
|
||||
// is this the test item which we use in several event handlers?
|
||||
bool IsTestItem(const wxTreeItemId& item)
|
||||
{
|
||||
// the test item is the first child folder
|
||||
return GetParent(item) == GetRootItem() && !GetPrevSibling(item);
|
||||
}
|
||||
|
||||
private:
|
||||
void AddItemsRecursively(const wxTreeItemId& idParent,
|
||||
size_t nChildren,
|
||||
|
@@ -23,9 +23,10 @@
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/window.h"
|
||||
#include "wx/msw/private.h"
|
||||
#endif
|
||||
|
||||
#include "wx/msw/private.h"
|
||||
|
||||
#include "wx/dcscreen.h"
|
||||
|
||||
|
||||
|
@@ -1231,13 +1231,21 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
||||
event.m_col = hdr->iSubItem;
|
||||
break;
|
||||
}
|
||||
|
||||
case LVN_DELETEALLITEMS:
|
||||
{
|
||||
// what's the sense of generating a wxWin event for this when
|
||||
// it's absolutely not portable?
|
||||
#if 0
|
||||
eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
|
||||
// NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
|
||||
event.m_itemIndex = -1;
|
||||
break;
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
// return TRUE to suppress all additional LVN_DELETEITEM
|
||||
// notifications - this makes deleting all items from a list ctrl
|
||||
// much faster
|
||||
*result = TRUE;
|
||||
return TRUE;
|
||||
|
||||
case LVN_DELETEITEM:
|
||||
{
|
||||
eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
|
||||
|
@@ -131,8 +131,8 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||
|
||||
m_windowId = (id == -1) ? NewControlId() : id;
|
||||
|
||||
DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_HASLINES | TVS_SHOWSELALWAYS ;
|
||||
|
||||
DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP |
|
||||
TVS_HASLINES | TVS_SHOWSELALWAYS;
|
||||
|
||||
bool want3D;
|
||||
WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
|
||||
@@ -792,7 +792,12 @@ wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item,
|
||||
|
||||
HWND hWnd = (HWND) TreeView_EditLabel(GetHwnd(), (HTREEITEM) (WXHTREEITEM) item);
|
||||
|
||||
wxCHECK_MSG( hWnd, NULL, _T("Can't edit tree ctrl label") );
|
||||
// this is not an error - the TVN_BEGINLABELEDIT handler might have
|
||||
// returned FALSE
|
||||
if ( !hWnd )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DeleteTextCtrl();
|
||||
|
||||
@@ -960,6 +965,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
||||
TV_DISPINFO *info = (TV_DISPINFO *)lParam;
|
||||
|
||||
event.m_item = (WXHTREEITEM) info->item.hItem;
|
||||
event.m_label = info->item.pszText;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -978,6 +984,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
||||
TV_DISPINFO *info = (TV_DISPINFO *)lParam;
|
||||
|
||||
event.m_item = (WXHTREEITEM)info->item.hItem;
|
||||
event.m_label = info->item.pszText;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1074,18 +1081,46 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
||||
bool processed = GetEventHandler()->ProcessEvent(event);
|
||||
|
||||
// post processing
|
||||
if ( hdr->code == TVN_DELETEITEM )
|
||||
switch ( hdr->code )
|
||||
{
|
||||
// NB: we might process this message using wxWindows event tables, but
|
||||
// due to overhead of wxWin event system we prefer to do it here
|
||||
// (otherwise deleting a tree with many items is just too slow)
|
||||
case TVN_DELETEITEM:
|
||||
{
|
||||
// NB: we might process this message using wxWindows event
|
||||
// tables, but due to overhead of wxWin event system we
|
||||
// prefer to do it here ourself (otherwise deleting a tree
|
||||
// with many items is just too slow)
|
||||
NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam;
|
||||
wxTreeItemData *data = (wxTreeItemData *)tv->itemOld.lParam;
|
||||
delete data; // may be NULL, ok
|
||||
|
||||
processed = TRUE; // Make sure we don't get called twice
|
||||
}
|
||||
break;
|
||||
|
||||
case TVN_BEGINLABELEDIT:
|
||||
// return TRUE to cancel label editing
|
||||
*result = !event.IsAllowed();
|
||||
break;
|
||||
|
||||
case TVN_ENDLABELEDIT:
|
||||
// return TRUE to set the label to the new string
|
||||
*result = event.IsAllowed();
|
||||
|
||||
// ensure that we don't have the text ctrl which is going to be
|
||||
// deleted any more
|
||||
DeleteTextCtrl();
|
||||
break;
|
||||
|
||||
case TVN_SELCHANGING:
|
||||
case TVN_ITEMEXPANDING:
|
||||
// return TRUE to prevent the action from happening
|
||||
*result = !event.IsAllowed();
|
||||
break;
|
||||
|
||||
//default:
|
||||
// for the other messages the return value is ignored and there is
|
||||
// nothing special to do
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
Reference in New Issue
Block a user