1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWidgets sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers)
33 #if !defined(__WXMSW__) // || wxUSE_XPM_IN_MSW
35 static char * icon1_xpm
[] = {
36 /* width height ncolors chars_per_pixel */
64 static char * icon2_xpm
[] = {
65 /* width height ncolors chars_per_pixel */
90 #include "wx/imaglist.h"
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
96 // the application icon
98 #include "mondrian.xpm"
101 // ----------------------------------------------------------------------------
102 // event tables and other macros for wxWidgets
103 // ----------------------------------------------------------------------------
105 // the event tables connect the wxWidgets events with the functions (event
106 // handlers) which process them. It can be also done at run-time, but for the
107 // simple menu events like this the static method is much simpler.
108 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
109 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
110 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
113 // Create a new application object: this macro will allow wxWidgets to create
114 // the application object during program execution (it's better than using a
115 // static object for many reasons) and also declares the accessor function
116 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
120 // ============================================================================
122 // ============================================================================
124 // ----------------------------------------------------------------------------
125 // the application class
126 // ----------------------------------------------------------------------------
128 // 'Main program' equivalent: the program execution "starts" here
131 // create the main application window
132 MyFrame
*frame
= new MyFrame(wxT("Tree Testing"),
133 wxPoint(50, 50), wxSize(450, 340));
135 // and show it (the frames, unlike simple controls, are not shown when
136 // created initially)
139 // success: wxApp::OnRun() will be called which will enter the main message
140 // loop and the application will run. If we returned false here, the
141 // application would exit immediately.
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
150 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
151 : wxFrame((wxFrame
*)NULL
, idMAIN_FRAME
, title
, pos
, size
)
154 m_scrolledWindow
= NULL
;
156 m_valueWindow
= NULL
;
158 // we need this in order to allow the about menu relocation, since ABOUT is
159 // not the default id of the about menu
160 wxApp::s_macAboutMenuItemId
= Minimal_About
;
163 m_scrolledWindow
= new wxSplitterScrolledWindow(this, idSCROLLED_WINDOW
, wxDefaultPosition
,
164 wxSize(300, 400), wxNO_BORDER
| wxCLIP_CHILDREN
| wxVSCROLL
);
165 m_splitter
= new wxThinSplitterWindow(m_scrolledWindow
, idSPLITTER_WINDOW
, wxDefaultPosition
,
166 wxDefaultSize
, wxSP_3DBORDER
| wxCLIP_CHILDREN
/* | wxSP_LIVE_UPDATE */);
167 m_splitter
->SetSashSize(2);
169 /* Note the wxTR_ROW_LINES style: draws horizontal lines between items */
170 m_tree
= new TestTree(m_splitter
, idTREE_CTRL
, wxDefaultPosition
,
171 wxDefaultSize
, wxTR_HAS_BUTTONS
| wxTR_NO_LINES
| wxNO_BORDER
| wxTR_ROW_LINES
);
172 m_valueWindow
= new TestValueWindow(m_splitter
, idVALUE_WINDOW
, wxDefaultPosition
,
173 wxDefaultSize
, wxNO_BORDER
);
174 m_splitter
->SplitVertically(m_tree
, m_valueWindow
);
175 //m_splitter->AdjustScrollbars();
176 m_splitter
->SetSashPosition(200);
177 m_scrolledWindow
->SetTargetWindow(m_tree
);
179 m_scrolledWindow
->EnableScrolling(false, false);
181 // Let the two controls know about each other
182 m_valueWindow
->SetTreeCtrl(m_tree
);
183 m_tree
->SetCompanionWindow(m_valueWindow
);
185 // set the frame icon
186 SetIcon(wxICON(mondrian
));
189 wxMenu
*menuFile
= new wxMenu(wxEmptyString
, wxMENU_TEAROFF
);
191 // the "About" item should be in the help menu
192 wxMenu
*helpMenu
= new wxMenu
;
193 helpMenu
->Append(Minimal_About
, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
195 menuFile
->Append(Minimal_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
197 // now append the freshly created menu to the menu bar...
198 wxMenuBar
*menuBar
= new wxMenuBar();
199 menuBar
->Append(menuFile
, wxT("&File"));
200 menuBar
->Append(helpMenu
, wxT("&Help"));
202 // ... and attach this menu bar to the frame
209 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
211 // true is to force the frame to close
215 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
218 msg
.Printf( wxT("This is the about dialog of splittree sample.\n")
219 wxT("Welcome to %s"), wxVERSION_STRING
);
221 wxMessageBox(msg
, wxT("About Tree Test"), wxOK
| wxICON_INFORMATION
, this);
228 IMPLEMENT_CLASS(TestTree
, wxRemotelyScrolledTreeCtrl
)
230 BEGIN_EVENT_TABLE(TestTree
, wxRemotelyScrolledTreeCtrl
)
233 TestTree::TestTree(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pt
,
234 const wxSize
& sz
, long style
):
235 wxRemotelyScrolledTreeCtrl(parent
, id
, pt
, sz
, style
)
237 m_imageList
= new wxImageList(16, 16, true);
238 #if !defined(__WXMSW__) // || wxUSE_XPM_IN_MSW
239 m_imageList
->Add(wxIcon(icon1_xpm
));
240 m_imageList
->Add(wxIcon(icon2_xpm
));
241 #elif defined(__WXMSW__)
242 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE
));
243 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_ICO_RESOURCE
));
245 #error "Sorry, we don't have icons available for this platforms."
247 SetImageList(m_imageList
);
250 // Add some dummy items
251 wxTreeItemId rootId
= AddRoot(_("Root"), -1, -1);
253 for (i
= 1; i
<= 20; i
++)
256 label
.Printf(wxT("Item %d"), i
);
257 wxTreeItemId id
= AppendItem(rootId
, label
, 0);
258 //SetItemImage( id, 1, wxTreeItemIcon_Expanded );
261 for (j
= 0; j
< 10; j
++)
262 AppendItem(id
, _("Child"), 1);
267 TestTree::~TestTree()
277 //IMPLEMENT_CLASS(TestValueWindow, wxWindow)
279 BEGIN_EVENT_TABLE(TestValueWindow
, wxTreeCompanionWindow
)
282 TestValueWindow::TestValueWindow(wxWindow
* parent
, wxWindowID id
,
286 wxTreeCompanionWindow(parent
, id
, pos
, sz
, style
)
288 SetBackgroundColour(* wxWHITE
);