X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/352d44d26856241d5e14dac630ab4473d18e05ef..fbe2ca438b746a509ca04c456166b984650ecaac:/contrib/samples/gizmos/splittree/tree.cpp?ds=sidebyside diff --git a/contrib/samples/gizmos/splittree/tree.cpp b/contrib/samples/gizmos/splittree/tree.cpp index a060a5f887..e3cc5486f6 100644 --- a/contrib/samples/gizmos/splittree/tree.cpp +++ b/contrib/samples/gizmos/splittree/tree.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: tree.cpp -// Purpose: Minimal wxWindows sample +// Purpose: Minimal wxWidgets sample // Author: Julian Smart // Modified by: // Created: 04/01/98 @@ -17,8 +17,7 @@ // headers // ---------------------------------------------------------------------------- #ifdef __GNUG__ - #pragma implementation "tree.cpp" - #pragma interface "tree.cpp" + #pragma implementation "tree.h" #endif // For compilers that support precompilation, includes "wx/wx.h". @@ -29,7 +28,7 @@ #endif // for all others, include the necessary headers (this file is usually all you -// need because it includes almost all "standard" wxWindows headers) +// need because it includes almost all "standard" wxWidgets headers) #ifndef WX_PRECOMP #include "wx/wx.h" #endif @@ -98,15 +97,15 @@ static char * icon2_xpm[] = { // resources // ---------------------------------------------------------------------------- // the application icon -#if defined(__WXGTK__) || defined(__WXMOTIF__) +#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) #include "mondrian.xpm" #endif // ---------------------------------------------------------------------------- -// event tables and other macros for wxWindows +// event tables and other macros for wxWidgets // ---------------------------------------------------------------------------- -// the event tables connect the wxWindows events with the functions (event +// the event tables connect the wxWidgets events with the functions (event // handlers) which process them. It can be also done at run-time, but for the // simple menu events like this the static method is much simpler. BEGIN_EVENT_TABLE(MyFrame, wxFrame) @@ -114,7 +113,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Minimal_About, MyFrame::OnAbout) END_EVENT_TABLE() -// Create a new application object: this macro will allow wxWindows to create +// Create a new application object: this macro will allow wxWidgets to create // the application object during program execution (it's better than using a // static object for many reasons) and also declares the accessor function // wxGetApp() which will return the reference of the right type (i.e. MyApp and @@ -133,17 +132,17 @@ IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { // create the main application window - MyFrame *frame = new MyFrame("Tree Testing", + MyFrame *frame = new MyFrame(wxT("Tree Testing"), wxPoint(50, 50), wxSize(450, 340)); // and show it (the frames, unlike simple controls, are not shown when // created initially) - frame->Show(TRUE); + frame->Show(true); // success: wxApp::OnRun() will be called which will enter the main message - // loop and the application will run. If we returned FALSE here, the + // loop and the application will run. If we returned false here, the // application would exit immediately. - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -155,7 +154,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, idMAIN_FRAME, title, pos, size) { m_splitter = NULL; - m_scrolledWindow = NULL; + m_scrolledWindow = NULL; m_tree = NULL; m_valueWindow = NULL; #ifdef __WXMAC__ @@ -165,41 +164,43 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) #endif m_scrolledWindow = new wxSplitterScrolledWindow(this, idSCROLLED_WINDOW, wxDefaultPosition, - wxDefaultSize, wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL); + wxSize(300, 400), wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL); m_splitter = new wxThinSplitterWindow(m_scrolledWindow, idSPLITTER_WINDOW, wxDefaultPosition, - wxDefaultSize, wxSP_3DBORDER | wxCLIP_CHILDREN /* | wxSP_LIVE_UPDATE */); - m_splitter->SetSashSize(2); - m_tree = new TestTree(m_splitter, idTREE_CTRL, wxDefaultPosition, - wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxNO_BORDER ); + wxDefaultSize, wxSP_3DBORDER | wxCLIP_CHILDREN /* | wxSP_LIVE_UPDATE */); + m_splitter->SetSashSize(2); + + /* Note the wxTR_ROW_LINES style: draws horizontal lines between items */ + m_tree = new TestTree(m_splitter , idTREE_CTRL, wxDefaultPosition, + wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxNO_BORDER | wxTR_ROW_LINES ); m_valueWindow = new TestValueWindow(m_splitter, idVALUE_WINDOW, wxDefaultPosition, - wxDefaultSize, wxNO_BORDER); + wxDefaultSize, wxNO_BORDER); m_splitter->SplitVertically(m_tree, m_valueWindow); - //m_splitter->AdjustScrollbars(); - m_splitter->SetSashPosition(200); - m_scrolledWindow->SetTargetWindow(m_tree); + //m_splitter->AdjustScrollbars(); + m_splitter->SetSashPosition(200); + m_scrolledWindow->SetTargetWindow(m_tree); - m_scrolledWindow->EnableScrolling(FALSE, FALSE); + m_scrolledWindow->EnableScrolling(false, false); - // Let the two controls know about each other - m_valueWindow->SetTreeCtrl(m_tree); - m_tree->SetCompanionWindow(m_valueWindow); + // Let the two controls know about each other + m_valueWindow->SetTreeCtrl(m_tree); + m_tree->SetCompanionWindow(m_valueWindow); // set the frame icon SetIcon(wxICON(mondrian)); // create a menu bar - wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF); + wxMenu *menuFile = new wxMenu(wxT(""), wxMENU_TEAROFF); // the "About" item should be in the help menu wxMenu *helpMenu = new wxMenu; - helpMenu->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog"); + helpMenu->Append(Minimal_About, wxT("&About...\tCtrl-A"), wxT("Show about dialog")); - menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program"); + menuFile->Append(Minimal_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program")); // now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); - menuBar->Append(menuFile, "&File"); - menuBar->Append(helpMenu, "&Help"); + menuBar->Append(menuFile, wxT("&File")); + menuBar->Append(helpMenu, wxT("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar); @@ -210,17 +211,17 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { - // TRUE is to force the frame to close - Close(TRUE); + // true is to force the frame to close + Close(true); } void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxString msg; - msg.Printf( _T("This is the about dialog of tree sample.\n") - _T("Welcome to %s"), wxVERSION_STRING); + msg.Printf( wxT("This is the about dialog of splittree sample.\n") + wxT("Welcome to %s"), wxVERSION_STRING); - wxMessageBox(msg, "About Tree Test", wxOK | wxICON_INFORMATION, this); + wxMessageBox(msg, wxT("About Tree Test"), wxOK | wxICON_INFORMATION, this); } /* @@ -230,14 +231,13 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) IMPLEMENT_CLASS(TestTree, wxRemotelyScrolledTreeCtrl) BEGIN_EVENT_TABLE(TestTree, wxRemotelyScrolledTreeCtrl) - EVT_PAINT(TestTree::OnPaint) END_EVENT_TABLE() TestTree::TestTree(wxWindow* parent, wxWindowID id, const wxPoint& pt, const wxSize& sz, long style): wxRemotelyScrolledTreeCtrl(parent, id, pt, sz, style) { - m_imageList = new wxImageList(16, 16, TRUE); + m_imageList = new wxImageList(16, 16, true); #if !defined(__WXMSW__) // || wxUSE_XPM_IN_MSW m_imageList->Add(wxIcon(icon1_xpm)); m_imageList->Add(wxIcon(icon2_xpm)); @@ -249,63 +249,28 @@ TestTree::TestTree(wxWindow* parent, wxWindowID id, const wxPoint& pt, #endif SetImageList(m_imageList); - - // Add some dummy items - wxTreeItemId rootId = AddRoot(_("Root"), -1, -1); - int i; - for (i = 1; i <= 20; i++) - { - wxString label; - label.Printf(wxT("Item %d"), i); - wxTreeItemId id = AppendItem(rootId, label, 0); - //SetItemImage( id, 1, wxTreeItemIcon_Expanded ); - - int j; - for (j = 0; j < 10; j++) - AppendItem(id, _("Child"), 1); - } - Expand(rootId); -} -TestTree::~TestTree() -{ - SetImageList(NULL); - delete m_imageList; + // Add some dummy items + wxTreeItemId rootId = AddRoot(_("Root"), -1, -1); + int i; + for (i = 1; i <= 20; i++) + { + wxString label; + label.Printf(wxT("Item %d"), i); + wxTreeItemId id = AppendItem(rootId, label, 0); + //SetItemImage( id, 1, wxTreeItemIcon_Expanded ); + + int j; + for (j = 0; j < 10; j++) + AppendItem(id, _("Child"), 1); + } + Expand(rootId); } -void TestTree::OnPaint(wxPaintEvent& event) +TestTree::~TestTree() { - wxPaintDC dc(this); - - wxTreeCtrl::OnPaint(event); - - // Reset the device origin since it may have been set - dc.SetDeviceOrigin(0, 0); - - wxSize sz = GetClientSize(); - - wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); - dc.SetPen(pen); - dc.SetBrush(* wxTRANSPARENT_BRUSH); - - wxSize clientSize = GetClientSize(); - wxRect itemRect; - int cy=0; - wxTreeItemId h, lastH; - for(h=GetFirstVisibleItem();h;h=GetNextVisible(h)) - { - if (GetBoundingRect(h, itemRect)) - { - cy = itemRect.GetTop(); - dc.DrawLine(0, cy, clientSize.x, cy); - lastH = h; - } - } - if (GetBoundingRect(lastH, itemRect)) - { - cy = itemRect.GetBottom(); - dc.DrawLine(0, cy, clientSize.x, cy); - } + SetImageList(NULL); + delete m_imageList; } /* @@ -323,5 +288,5 @@ TestValueWindow::TestValueWindow(wxWindow* parent, wxWindowID id, long style): wxTreeCompanionWindow(parent, id, pos, sz, style) { - SetBackgroundColour(* wxWHITE); + SetBackgroundColour(* wxWHITE); }