]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/treectrl/treectrl.cpp
added SetString(), deprecated SetLabel()
[wxWidgets.git] / samples / treectrl / treectrl.cpp
index 9c7c1c0d637fbb0a18f538d52d440dfbd446ce6b..0a62c840820fbdb617831dfaf1cec5bfebc6c6d8 100644 (file)
 #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!", \
-                                          "Tree sample error",              \
-                                          wxOK | wxICON_EXCLAMATION,        \
-                                          this);                            \
-                             return;                                        \
+#define CHECK_ITEM( item ) if ( !item.IsOk() ) {                                 \
+                             wxMessageBox(wxT("Please select some item first!"), \
+                                          wxT("Tree sample error"),              \
+                                          wxOK | wxICON_EXCLAMATION,             \
+                                          this);                                 \
+                             return;                                             \
                            }
 
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
@@ -75,6 +75,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     MENU_LINK(TogHideRoot)
     MENU_LINK(TogRootLines)
     MENU_LINK(TogBorder)
+    MENU_LINK(TogFullHighlight)
     MENU_LINK(Dump)
 #ifndef NO_MULTIPLE_SELECTION
     MENU_LINK(DumpSelected)
@@ -143,7 +144,7 @@ IMPLEMENT_APP(MyApp)
 bool MyApp::OnInit()
 {
     // Create the main frame window
-    MyFrame *frame = new MyFrame("wxTreeCtrl Test", 50, 50, 450, 600);
+    MyFrame *frame = new MyFrame(wxT("wxTreeCtrl Test"), 50, 50, 450, 600);
 
     // Show the frame
     frame->Show(TRUE);
@@ -173,9 +174,9 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
            *tree_menu = new wxMenu,
            *item_menu = new wxMenu;
 
-    file_menu->Append(TreeTest_About, "&About...");
+    file_menu->Append(TreeTest_About, wxT("&About..."));
     file_menu->AppendSeparator();
-    file_menu->Append(TreeTest_Quit, "E&xit\tAlt-X");
+    file_menu->Append(TreeTest_Quit, wxT("E&xit\tAlt-X"));
 
     style_menu->Append(TreeTest_TogButtons, "Toggle &normal buttons");
     style_menu->Append(TreeTest_TogTwist, "Toggle &twister buttons");
@@ -185,12 +186,13 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
     style_menu->Append(TreeTest_TogRootLines, "Toggle &lines at root");
     style_menu->Append(TreeTest_TogHideRoot, "Toggle &hidden root");
     style_menu->Append(TreeTest_TogBorder, "Toggle &item border");
+    style_menu->Append(TreeTest_TogFullHighlight, "Toggle &full row highlight");
     style_menu->Append(TreeTest_TogEdit, "Toggle &edit mode");
 #ifndef NO_MULTIPLE_SELECTION
-    style_menu->Append(TreeTest_ToggleSel, "Toggle &selection mode");
+    style_menu->Append(TreeTest_ToggleSel, wxT("Toggle &selection mode"));
 #endif // NO_MULTIPLE_SELECTION
-    style_menu->Append(TreeTest_ToggleImages, "Toggle show ima&ges");
-    style_menu->Append(TreeTest_SetImageSize, "Set image si&ze...");
+    style_menu->Append(TreeTest_ToggleImages, wxT("Toggle show ima&ges"));
+    style_menu->Append(TreeTest_SetImageSize, wxT("Set image si&ze..."));
 
     tree_menu->Append(TreeTest_Recreate, "&Recreate the tree");
     tree_menu->Append(TreeTest_CollapseAndReset, "C&ollapse and reset");
@@ -243,8 +245,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
 
     m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl,
                                 wxDefaultPosition, wxDefaultSize,
-                                wxTR_TWIST_BUTTONS | wxTR_NO_LINES |
-                                wxTR_EDIT_LABELS |
+                                wxTR_DEFAULT_STYLE | wxTR_EDIT_LABELS |
 #ifndef NO_VARIABLE_HEIGHT
                                 wxTR_HAS_VARIABLE_ROW_HEIGHT |
 #endif
@@ -401,7 +402,7 @@ void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event))
 
     for ( size_t n = 0; n < count; n++ )
     {
-        wxLogMessage("\t%s", m_treeCtrl->GetItemText(array.Item(n)).c_str());
+        wxLogMessage(wxT("\t%s"), m_treeCtrl->GetItemText(array.Item(n)).c_str());
     }
 }
 
@@ -484,6 +485,7 @@ void MyFrame::OnToggleImages(wxCommandEvent& event)
 
 void MyFrame::OnToggleButtons(wxCommandEvent& event)
 {
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
     if ( wxGetApp().ShowButtons() )
     {
         m_treeCtrl->CreateButtonsImageList(-1);
@@ -494,6 +496,7 @@ void MyFrame::OnToggleButtons(wxCommandEvent& event)
         m_treeCtrl->CreateButtonsImageList(15);
         wxGetApp().SetShowButtons(TRUE);
     }
+#endif
 }
 
 void MyFrame::OnCollapseAndReset(wxCommandEvent& event)
@@ -517,7 +520,7 @@ void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event))
     static int s_num = 0;
 
     wxString text;
-    text.Printf("Item #%d", ++s_num);
+    text.Printf(wxT("Item #%d"), ++s_num);
 
     m_treeCtrl->AppendItem(m_treeCtrl->GetRootItem(),
                            text /*,
@@ -632,6 +635,7 @@ void MyTreeCtrl::CreateImageList(int size)
 
 void MyTreeCtrl::CreateButtonsImageList(int size)
 {
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
     if ( size == -1 )
     {
         SetButtonsImageList(NULL);
@@ -672,6 +676,7 @@ void MyTreeCtrl::CreateButtonsImageList(int size)
 #endif // MSW/!MSW
 
     AssignButtonsImageList(images);
+#endif
 }
 
 MyTreeCtrl::~MyTreeCtrl()
@@ -706,9 +711,9 @@ void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId& idParent,
         {
             // at depth 1 elements won't have any more children
             if ( hasChildren )
-                str.Printf("%s child %d", "Folder", n + 1);
+                str.Printf(wxT("%s child %d"), wxT("Folder"), n + 1);
             else
-                str.Printf("%s child %d.%d", "File", folder, n + 1);
+                str.Printf(wxT("%s child %d.%d"), wxT("File"), folder, n + 1);
 
             // here we pass to AppendItem() normal and selected item images (we
             // suppose that selected image follows the normal one in the enum)
@@ -802,11 +807,11 @@ void MyTreeCtrl::DoToggleIcon(const wxTreeItemId& item)
 
 
 // avoid repetition
-#define TREE_EVENT_HANDLER(name)                            \
-void MyTreeCtrl::name(wxTreeEvent& event)                   \
-{                                                           \
-    wxLogMessage(#name);                                    \
-    event.Skip();                                           \
+#define TREE_EVENT_HANDLER(name)                                 \
+void MyTreeCtrl::name(wxTreeEvent& event)                        \
+{                                                                \
+    wxLogMessage(wxT(#name));                                    \
+    event.Skip();                                                \
 }
 
 TREE_EVENT_HANDLER(OnBeginRDrag)
@@ -829,14 +834,14 @@ void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
     {
         m_draggedItem = event.GetItem();
 
-        wxLogMessage("OnBeginDrag: started dragging %s",
+        wxLogMessage(wxT("OnBeginDrag: started dragging %s"),
                      GetItemText(m_draggedItem).c_str());
 
         event.Allow();
     }
     else
     {
-        wxLogMessage("OnBeginDrag: this item can't be dragged.");
+        wxLogMessage(wxT("OnBeginDrag: this item can't be dragged."));
     }
 }
 
@@ -855,13 +860,13 @@ void MyTreeCtrl::OnEndDrag(wxTreeEvent& event)
 
     if ( !itemDst.IsOk() )
     {
-        wxLogMessage("OnEndDrag: can't drop here.");
+        wxLogMessage(wxT("OnEndDrag: can't drop here."));
 
         return;
     }
 
     wxString text = GetItemText(itemSrc);
-    wxLogMessage("OnEndDrag: '%s' copied to '%s'.",
+    wxLogMessage(wxT("OnEndDrag: '%s' copied to '%s'."),
                  text.c_str(), GetItemText(itemDst).c_str());
 
     // just do append here - we could also insert it just before/after the item
@@ -877,13 +882,13 @@ void MyTreeCtrl::OnEndDrag(wxTreeEvent& event)
 
 void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event)
 {
-    wxLogMessage("OnBeginLabelEdit");
+    wxLogMessage(wxT("OnBeginLabelEdit"));
 
     // for testing, prevent this item's label editing
     wxTreeItemId itemId = event.GetItem();
     if ( IsTestItem(itemId) )
     {
-        wxMessageBox("You can't edit this item.");
+        wxMessageBox(wxT("You can't edit this item."));
 
         event.Veto();
     }
@@ -891,12 +896,12 @@ void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event)
 
 void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event)
 {
-    wxLogMessage("OnEndLabelEdit");
+    wxLogMessage(wxT("OnEndLabelEdit"));
 
     // don't allow anything except letters in the labels
     if ( !event.GetLabel().IsWord() )
     {
-        wxMessageBox("The label should contain only letters.");
+        wxMessageBox(wxT("The label should contain only letters."));
 
         event.Veto();
     }
@@ -904,13 +909,13 @@ void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event)
 
 void MyTreeCtrl::OnItemCollapsing(wxTreeEvent& event)
 {
-    wxLogMessage("OnItemCollapsing");
+    wxLogMessage(wxT("OnItemCollapsing"));
 
     // for testing, prevent the user from collapsing the first child folder
     wxTreeItemId itemId = event.GetItem();
     if ( IsTestItem(itemId) )
     {
-        wxMessageBox("You can't collapse this item.");
+        wxMessageBox(wxT("You can't collapse this item."));
 
         event.Veto();
     }
@@ -927,7 +932,7 @@ void MyTreeCtrl::OnItemActivated(wxTreeEvent& event)
         item->ShowInfo(this);
     }
 
-    wxLogMessage("OnItemActivated");
+    wxLogMessage(wxT("OnItemActivated"));
 }
 
 void MyTreeCtrl::OnItemRightClick(wxTreeEvent& event)
@@ -966,24 +971,24 @@ void MyTreeCtrl::OnRMouseDClick(wxMouseEvent& event)
 {
     wxTreeItemId id = HitTest(event.GetPosition());
     if ( !id )
-        wxLogMessage("No item under mouse");
+        wxLogMessage(wxT("No item under mouse"));
     else
     {
         MyTreeItemData *item = (MyTreeItemData *)GetItemData(id);
         if ( item )
-            wxLogMessage("Item '%s' under mouse", item->GetDesc());
+            wxLogMessage(wxT("Item '%s' under mouse"), item->GetDesc());
     }
 }
 
-static inline const char *Bool2String(bool b)
+static inline const wxChar *Bool2String(bool b)
 {
-    return b ? "" : "not ";
+    return b ? wxT("") : wxT("not ");
 }
 
 void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
 {
-    wxLogMessage("Item '%s': %sselected, %sexpanded, %sbold,\n"
-                 "%u children (%u immediately under this item).",
+    wxLogMessage(wxT("Item '%s': %sselected, %sexpanded, %sbold,\n")
+                 wxT("%u children (%u immediately under this item)."),
                  m_desc.c_str(),
                  Bool2String(tree->IsSelected(GetId())),
                  Bool2String(tree->IsExpanded(GetId())),