]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/gizmos/splittree/tree.cpp
attempt to correct bogus tex2rtf warning about unmatched brackets in htprintmacros.inc
[wxWidgets.git] / contrib / samples / gizmos / splittree / tree.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tree.cpp
3 // Purpose: Minimal wxWidgets sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers)
29 #ifndef WX_PRECOMP
30 #include "wx/wx.h"
31 #endif
32
33 #if !defined(__WXMSW__) // || wxUSE_XPM_IN_MSW
34 /* Closed folder */
35 static char * icon1_xpm[] = {
36 /* width height ncolors chars_per_pixel */
37 "16 16 6 1",
38 /* colors */
39 " s None c None",
40 ". c #000000",
41 "+ c #c0c0c0",
42 "@ c #808080",
43 "# c #ffff00",
44 "$ c #ffffff",
45 /* pixels */
46 " ",
47 " @@@@@ ",
48 " @#+#+#@ ",
49 " @#+#+#+#@@@@@@ ",
50 " @$$$$$$$$$$$$@.",
51 " @$#+#+#+#+#+#@.",
52 " @$+#+#+#+#+#+@.",
53 " @$#+#+#+#+#+#@.",
54 " @$+#+#+#+#+#+@.",
55 " @$#+#+#+#+#+#@.",
56 " @$+#+#+#+#+#+@.",
57 " @$#+#+#+#+#+#@.",
58 " @@@@@@@@@@@@@@.",
59 " ..............",
60 " ",
61 " "};
62
63 /* File */
64 static char * icon2_xpm[] = {
65 /* width height ncolors chars_per_pixel */
66 "16 16 3 1",
67 /* colors */
68 " s None c None",
69 ". c #000000",
70 "+ c #ffffff",
71 /* pixels */
72 " ",
73 " ........ ",
74 " .++++++.. ",
75 " .+.+.++.+. ",
76 " .++++++.... ",
77 " .+.+.+++++. ",
78 " .+++++++++. ",
79 " .+.+.+.+.+. ",
80 " .+++++++++. ",
81 " .+.+.+.+.+. ",
82 " .+++++++++. ",
83 " .+.+.+.+.+. ",
84 " .+++++++++. ",
85 " ........... ",
86 " ",
87 " "};
88 #endif
89
90 #include "wx/imaglist.h"
91 #include "tree.h"
92
93 // ----------------------------------------------------------------------------
94 // resources
95 // ----------------------------------------------------------------------------
96 // the application icon
97 #ifndef __WXMSW__
98 #include "mondrian.xpm"
99 #endif
100
101 // ----------------------------------------------------------------------------
102 // event tables and other macros for wxWidgets
103 // ----------------------------------------------------------------------------
104
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)
111 END_EVENT_TABLE()
112
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
117 // not wxApp)
118 IMPLEMENT_APP(MyApp)
119
120 // ============================================================================
121 // implementation
122 // ============================================================================
123
124 // ----------------------------------------------------------------------------
125 // the application class
126 // ----------------------------------------------------------------------------
127
128 // 'Main program' equivalent: the program execution "starts" here
129 bool MyApp::OnInit()
130 {
131 // create the main application window
132 MyFrame *frame = new MyFrame(wxT("Tree Testing"),
133 wxPoint(50, 50), wxSize(450, 340));
134
135 // and show it (the frames, unlike simple controls, are not shown when
136 // created initially)
137 frame->Show(true);
138
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.
142 return true;
143 }
144
145 // ----------------------------------------------------------------------------
146 // main frame
147 // ----------------------------------------------------------------------------
148
149 // frame constructor
150 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
151 : wxFrame((wxFrame *)NULL, idMAIN_FRAME, title, pos, size)
152 {
153 m_splitter = NULL;
154 m_scrolledWindow = NULL;
155 m_tree = NULL;
156 m_valueWindow = NULL;
157 #ifdef __WXMAC__
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;
161 #endif
162
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);
168
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);
178
179 m_scrolledWindow->EnableScrolling(false, false);
180
181 // Let the two controls know about each other
182 m_valueWindow->SetTreeCtrl(m_tree);
183 m_tree->SetCompanionWindow(m_valueWindow);
184
185 // set the frame icon
186 SetIcon(wxICON(mondrian));
187
188 // create a menu bar
189 wxMenu *menuFile = new wxMenu(wxEmptyString, wxMENU_TEAROFF);
190
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"));
194
195 menuFile->Append(Minimal_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
196
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"));
201
202 // ... and attach this menu bar to the frame
203 SetMenuBar(menuBar);
204 }
205
206
207 // event handlers
208
209 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
210 {
211 // true is to force the frame to close
212 Close(true);
213 }
214
215 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
216 {
217 wxString msg;
218 msg.Printf( wxT("This is the about dialog of splittree sample.\n")
219 wxT("Welcome to %s"), wxVERSION_STRING);
220
221 wxMessageBox(msg, wxT("About Tree Test"), wxOK | wxICON_INFORMATION, this);
222 }
223
224 /*
225 * TesTree
226 */
227
228 IMPLEMENT_CLASS(TestTree, wxRemotelyScrolledTreeCtrl)
229
230 BEGIN_EVENT_TABLE(TestTree, wxRemotelyScrolledTreeCtrl)
231 END_EVENT_TABLE()
232
233 TestTree::TestTree(wxWindow* parent, wxWindowID id, const wxPoint& pt,
234 const wxSize& sz, long style):
235 wxRemotelyScrolledTreeCtrl(parent, id, pt, sz, style)
236 {
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));
244 #else
245 #error "Sorry, we don't have icons available for this platforms."
246 #endif
247 SetImageList(m_imageList);
248
249
250 // Add some dummy items
251 wxTreeItemId rootId = AddRoot(_("Root"), -1, -1);
252 int i;
253 for (i = 1; i <= 20; i++)
254 {
255 wxString label;
256 label.Printf(wxT("Item %d"), i);
257 wxTreeItemId id = AppendItem(rootId, label, 0);
258 //SetItemImage( id, 1, wxTreeItemIcon_Expanded );
259
260 int j;
261 for (j = 0; j < 10; j++)
262 AppendItem(id, _("Child"), 1);
263 }
264 Expand(rootId);
265 }
266
267 TestTree::~TestTree()
268 {
269 SetImageList(NULL);
270 delete m_imageList;
271 }
272
273 /*
274 * TestValueWindow
275 */
276
277 //IMPLEMENT_CLASS(TestValueWindow, wxWindow)
278
279 BEGIN_EVENT_TABLE(TestValueWindow, wxTreeCompanionWindow)
280 END_EVENT_TABLE()
281
282 TestValueWindow::TestValueWindow(wxWindow* parent, wxWindowID id,
283 const wxPoint& pos,
284 const wxSize& sz,
285 long style):
286 wxTreeCompanionWindow(parent, id, pos, sz, style)
287 {
288 SetBackgroundColour(* wxWHITE);
289 }