#include "wx/wx.h"
#endif
-// under Windows the icons are in the .rc file
-#ifndef __WXMSW__
- #include "icon1.xpm"
- #include "icon2.xpm"
- #include "mondrian.xpm"
-#endif
-
#include "wx/log.h"
+#include "wx/image.h"
#include "wx/imaglist.h"
#include "wx/treectrl.h"
#include "treetest.h"
+#ifdef __WXMSW__
+ #define NO_ADVANCED_FEATURES
+#endif
+
+// under Windows the icons are in the .rc file
+#ifndef __WXMSW__
+ #include "icon1.xpm"
+ #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!", \
EVT_MENU(TreeTest_Quit, MyFrame::OnQuit)
EVT_MENU(TreeTest_About, MyFrame::OnAbout)
EVT_MENU(TreeTest_Dump, MyFrame::OnDump)
+ EVT_MENU(TreeTest_Dump_Selected, MyFrame::OnDumpSelected)
EVT_MENU(TreeTest_Rename, MyFrame::OnRename)
EVT_MENU(TreeTest_Sort, MyFrame::OnSort)
EVT_MENU(TreeTest_SortRev, MyFrame::OnSortRev)
tree_menu->Append(TreeTest_DecSpacing, "Reduce spacing by 5 points\tCtrl-R");
item_menu->Append(TreeTest_Dump, "&Dump item children");
- item_menu->AppendSeparator();
+#ifndef NO_ADVANCED_FEATURES
+ item_menu->Append(TreeTest_Dump_Selected, "Dump selected items\tAlt-S");
+#endif
item_menu->Append(TreeTest_Rename, "&Rename item...");
+
item_menu->AppendSeparator();
item_menu->Append(TreeTest_Bold, "Make item &bold");
item_menu->Append(TreeTest_UnBold, "Make item ¬ bold");
m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl,
wxDefaultPosition, wxDefaultSize,
- wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
+ wxTR_HAS_BUTTONS |
+ wxTR_EDIT_LABELS |
+#ifndef NO_ADVANCED_FEATURES
+ wxTR_MULTIPLE |
+ wxTR_HAS_VARIABLE_ROW_HEIGHT |
+#endif
+ wxSUNKEN_BORDER);
wxTextCtrl *textCtrl = new wxTextCtrl(this, -1, "",
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxSUNKEN_BORDER);
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);
}
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);
{
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)
m_treeCtrl->GetItemsRecursively(root, -1);
}
+void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event))
+{
+#ifndef NO_ADVANCED_FEATURES
+ wxArrayTreeItemIds array;
+
+ m_treeCtrl->GetSelections(array);
+ size_t nos=array.Count();
+ wxLogMessage(wxString("items selected : ")<< (int)nos);
+
+ for (size_t n=0; n<nos; ++n)
+ wxLogMessage(m_treeCtrl->GetItemText(array.Item(n)));
+#endif
+}
+
void MyFrame::DoSetBold(bool bold)
{
wxTreeItemId item = m_treeCtrl->GetSelection();
text.Printf("Item #%d", ++s_num);
m_treeCtrl->AppendItem(m_treeCtrl->GetRootItem(),
- text,
- MyTreeCtrl::TreeCtrlIcon_File);
+ text /*,
+ MyTreeCtrl::TreeCtrlIcon_File */ );
}
void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event))
long style)
: wxTreeCtrl(parent, id, pos, size, style)
{
+#if (USE_TR_HAS_VARIABLE_ROW_HIGHT && wxUSE_LIBJPEG)
+ wxImage::AddHandler(new wxJPEGHandler);
+ wxImage image;
+
+ image.LoadFile(wxString("horse.jpg"), wxBITMAP_TYPE_JPEG );
+#endif
+
m_reverseSort = FALSE;
// Make an image list containing small icons
#if defined(__WXMSW__) && defined(__WIN16__)
// This is required in 16-bit Windows mode only because we can't load a specific (16x16)
// icon image, so it comes out stretched
+# if USE_TR_HAS_VARIABLE_ROW_HIGHT
+ m_imageListNormal->Add(image.ConvertToBitmap());
+# else
m_imageListNormal->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE));
+# endif
m_imageListNormal->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE));
#else
+# if USE_TR_HAS_VARIABLE_ROW_HIGHT
+ m_imageListNormal->Add(image.ConvertToBitmap());
+# else
m_imageListNormal->Add(wxICON(icon1));
+# endif
m_imageListNormal->Add(wxICON(icon2));
#endif
else
str.Printf("%s child %d", "Folder", n + 1);
- int image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder;
+// int image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder;
+ int image = depth == 1 ? -1 : TreeCtrlIcon_Folder;
wxTreeItemId id = AppendItem(idParent, str, image, image,
new MyTreeItemData(str));
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)
#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.");